refactor: template renderer cleanup

This commit is contained in:
Marc 2024-09-21 13:16:15 -04:00
parent c05b34f4cd
commit b3b56754c2
Signed by: marc
GPG key ID: 048E042F22B5DC79

View file

@ -1,3 +1,10 @@
// Template rendering
//
// Abstracts the rendering of static HTML templates.
// Render(...) handles rendering the provided template with the
// default partial templates (header, footer, general base...), handles
// getting the paths to those template files and feeding the data (including
// some internally-generated context) when hydrating the template.
package main package main
import ( import (
@ -8,6 +15,15 @@ import (
"time" "time"
) )
type RenderMeta struct {
RenderStart time.Time
}
type RenderContext struct {
Data interface{}
Meta RenderMeta
}
func getRenderDuration(start time.Time) time.Duration { func getRenderDuration(start time.Time) time.Duration {
return time.Now().Sub(start) return time.Now().Sub(start)
} }
@ -35,14 +51,7 @@ func Render(w io.Writer, templateName string, data interface{}) error {
return err return err
} }
type RenderMeta struct { renderContext := RenderContext{Data: data, Meta: RenderMeta{RenderStart: start}}
RenderStart time.Time
}
type RenderContext struct { return tmpl.ExecuteTemplate(w, "base", renderContext)
Data interface{}
Meta RenderMeta
}
return tmpl.ExecuteTemplate(w, "base", RenderContext{Data: data, Meta: RenderMeta{RenderStart: start}})
} }