refactor: template renderer cleanup
This commit is contained in:
parent
c05b34f4cd
commit
b3b56754c2
1 changed files with 18 additions and 9 deletions
|
@ -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}})
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue