Remove templating completely

This commit is contained in:
Jan Bader 2022-01-17 22:17:23 +00:00
parent aa33c148cb
commit 6d49a549a0
2 changed files with 0 additions and 51 deletions

View File

@ -31,12 +31,6 @@ func (h *Handler) Serve() {
router := gin.Default() router := gin.Default()
router.FuncMap["now"] = time.Now router.FuncMap["now"] = time.Now
templates, err := NewTemplates(router.FuncMap)
if err != nil {
panic(err)
}
router.HTMLRender = templates
static, err := fs.Sub(web.Static, "dist") static, err := fs.Sub(web.Static, "dist")
if err != nil { if err != nil {
panic("couldn't open static files") panic("couldn't open static files")

View File

@ -1,45 +0,0 @@
package http
import (
"fmt"
"html/template"
"io/fs"
"git.javil.eu/jacob1123/budgeteer/web"
"github.com/gin-gonic/gin/render"
)
type Templates struct {
templates map[string]*template.Template
}
func NewTemplates(funcMap template.FuncMap) (*Templates, error) {
templates, err := fs.Glob(web.Templates, "*.tpl")
if err != nil {
return nil, fmt.Errorf("glob: %w", err)
}
result := &Templates{
templates: make(map[string]*template.Template, 0),
}
pages, err := fs.Glob(web.Templates, "*.html")
for _, page := range pages {
allTemplates := append(templates, page)
tpl, err := template.New(page).Funcs(funcMap).ParseFS(web.Templates, allTemplates...)
fmt.Printf("page: %s, templates: %v\n", page, templates)
if err != nil {
return nil, err
}
result.templates[page] = tpl
}
return result, nil
}
func (tpl *Templates) Instance(name string, obj interface{}) render.Render {
return render.HTML{
Template: tpl.templates[name],
Name: name,
Data: obj,
}
}