This commit is contained in:
2017-11-10 12:39:55 +01:00
commit 5a752618c3
579 changed files with 81271 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
package templates
import (
"html/template"
"os"
"path/filepath"
"fornaxian.com/pixeldrain-web/conf"
"fornaxian.com/pixeldrain-web/log"
)
var templates *template.Template
var templatePaths []string
// ParseTemplates parses the templates in the template directory which is
// defined in the config file
func ParseTemplates() {
filepath.Walk(conf.TemplateDir(), func(path string, f os.FileInfo, err error) error {
if f.IsDir() {
return nil
}
templatePaths = append(templatePaths, path)
log.Info("Template found: %s", path)
return nil
})
tpl := template.New("")
// Import template functions from funcs.go
tpl = tpl.Funcs(funcMap)
var err error
tpl, err = tpl.ParseFiles(templatePaths...)
if err != nil {
log.Error("Template parsing failed: %v", err)
}
// Swap out the old templates with the new templates, to minimize
// modifications to the original variable.
templates = tpl
}
// Get returns the templates, so they can be used to render views
func Get() *template.Template {
return templates
}