feat: metadata draft
This commit is contained in:
@ -67,7 +67,7 @@ func (tm *TemplateManager) GetTemplate(td *TemplateData) (*template.Template, er
|
||||
return tmpl, nil
|
||||
}
|
||||
|
||||
func (tm *TemplateManager) Render(w http.ResponseWriter, name string, data interface{}) error {
|
||||
func (tm *TemplateManager) Render(w http.ResponseWriter, name string, data any) error {
|
||||
// Build the template files - include all necessary templates
|
||||
var files []string
|
||||
|
||||
@ -77,6 +77,9 @@ func (tm *TemplateManager) Render(w http.ResponseWriter, name string, data inter
|
||||
// Include noteList template (used by index)
|
||||
files = append(files, tm.buildTemplatePath("noteList"))
|
||||
|
||||
// Include metadata template
|
||||
files = append(files, tm.buildTemplatePath("metadata"))
|
||||
|
||||
// Add the specific template
|
||||
files = append(files, tm.buildTemplatePath(name))
|
||||
|
||||
|
||||
@ -100,6 +100,7 @@ func TestTemplateManagerRender(t *testing.T) {
|
||||
writeTemplate(t, baseDir, "base.tmpl", `{{ define "base" }}<html>{{ template "content" . }}</html>{{ end }}`)
|
||||
writeTemplate(t, baseDir, "noteList.tmpl", `{{ define "noteList" }}notes{{ end }}`)
|
||||
writeTemplate(t, baseDir, "index.tmpl", `{{ define "content" }}hello{{ end }}`)
|
||||
writeTemplate(t, baseDir, "metadata.tmpl", `{{ define "noteList" }}notes{{ end }}`)
|
||||
|
||||
tm := NewTemplateManager(baseDir)
|
||||
rec := httptest.NewRecorder()
|
||||
@ -126,6 +127,7 @@ func TestTemplateManagerRender_MissingTemplate(t *testing.T) {
|
||||
baseDir := t.TempDir()
|
||||
writeTemplate(t, baseDir, "base.tmpl", `{{ define "base" }}<html>{{ template "content" . }}</html>{{ end }}`)
|
||||
writeTemplate(t, baseDir, "noteList.tmpl", `{{ define "noteList" }}notes{{ end }}`)
|
||||
writeTemplate(t, baseDir, "metadata.tmpl", `{{ define "noteList" }}notes{{ end }}`)
|
||||
|
||||
tm := NewTemplateManager(baseDir)
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
Reference in New Issue
Block a user