diff --git a/templates.go b/render_templates.go similarity index 54% rename from templates.go rename to render_templates.go index 6575506..9bbf135 100644 --- a/templates.go +++ b/render_templates.go @@ -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 import ( @@ -8,6 +15,15 @@ import ( "time" ) +type RenderMeta struct { + RenderStart time.Time +} + +type RenderContext struct { + Data interface{} + Meta RenderMeta +} + func getRenderDuration(start time.Time) time.Duration { return time.Now().Sub(start) } @@ -35,14 +51,7 @@ func Render(w io.Writer, templateName string, data interface{}) error { return err } - type RenderMeta struct { - RenderStart time.Time - } + renderContext := RenderContext{Data: data, Meta: RenderMeta{RenderStart: start}} - type RenderContext struct { - Data interface{} - Meta RenderMeta - } - - return tmpl.ExecuteTemplate(w, "base", RenderContext{Data: data, Meta: RenderMeta{RenderStart: start}}) + return tmpl.ExecuteTemplate(w, "base", renderContext) }