summaryrefslogtreecommitdiffstats
path: root/cmd/web/templates.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/web/templates.go')
-rw-r--r--cmd/web/templates.go41
1 files changed, 39 insertions, 2 deletions
diff --git a/cmd/web/templates.go b/cmd/web/templates.go
index 86e136d..2457053 100644
--- a/cmd/web/templates.go
+++ b/cmd/web/templates.go
@@ -1,7 +1,44 @@
package main
-import "github.com/yulqen/ded-go-core/internal/models"
+import (
+ "html/template"
+ "path/filepath"
-type operationsTemplateData struct {
+ "github.com/yulqen/ded-go-core/internal/models"
+)
+
+type templateData struct {
Operations []models.Operation
}
+
+func newTemplateCache() (map[string]*template.Template, error) {
+ cache := map[string]*template.Template{}
+
+ // get a slice of filepaths match the pattern for our page templates
+ // e.g. [ui/html/pages/home.tmpl.html ui/html/pages/view.tmpl.html]
+ pages, err := filepath.Glob("./ui/html/pages/*.html")
+ if err != nil {
+ return nil, err
+ }
+
+ // loop through the page filepaths one by one
+ for _, page := range pages {
+ // extract "home.tmp.html" from the full filepath.
+ name := filepath.Base(page)
+
+ files := []string{
+ "./ui/html/base.tmpl.html",
+ "./ui/html/partials/nav.tmpl.html",
+ page,
+ }
+
+ ts, err := template.ParseFiles(files...)
+ if err != nil {
+ return nil, err
+ }
+
+ cache[name] = ts
+ }
+
+ return cache, nil
+}