diff options
author | Simon Ser <contact@emersion.fr> | 2019-12-04 18:30:01 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-12-04 18:30:01 +0100 |
commit | e94b1311ded705b0af3a6977cf5fb248a9530387 (patch) | |
tree | 9ebf02e45469967c6f05300cfc5436cbee2e850f /template.go | |
parent | 4ab5fb7f65fe8d8f0b291dbead9f0134a28eaba2 (diff) | |
download | alps-e94b1311ded705b0af3a6977cf5fb248a9530387.tar.gz alps-e94b1311ded705b0af3a6977cf5fb248a9530387.zip |
Add basic theme support
References: https://todo.sr.ht/~sircmpwn/koushin/1
Diffstat (limited to 'template.go')
-rw-r--r-- | template.go | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/template.go b/template.go index 2581da0..f12e2ec 100644 --- a/template.go +++ b/template.go @@ -9,6 +9,7 @@ import ( ) type tmpl struct { + // TODO: add support for multiple themes t *template.Template } @@ -16,8 +17,8 @@ func (t *tmpl) Render(w io.Writer, name string, data interface{}, c echo.Context return t.t.ExecuteTemplate(w, name, data) } -func loadTemplates() (*tmpl, error) { - t, err := template.New("drmdb").Funcs(template.FuncMap{ +func loadTemplates(logger echo.Logger, themeName string) (*tmpl, error) { + base, err := template.New("").Funcs(template.FuncMap{ "tuple": func(values ...interface{}) []interface{} { return values }, @@ -25,5 +26,21 @@ func loadTemplates() (*tmpl, error) { return url.PathEscape(s) }, }).ParseGlob("public/*.html") - return &tmpl{t}, err + if err != nil { + return nil, err + } + + theme, err := base.Clone() + if err != nil { + return nil, err + } + + if themeName != "" { + logger.Printf("Loading theme \"%s\"", themeName) + if _, err := theme.ParseGlob("public/themes/" + themeName + "/*.html"); err != nil { + return nil, err + } + } + + return &tmpl{theme}, err } |