Remove templating completely
This commit is contained in:
		| @@ -31,12 +31,6 @@ func (h *Handler) Serve() { | ||||
| 	router := gin.Default() | ||||
| 	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") | ||||
| 	if err != nil { | ||||
| 		panic("couldn't open static files") | ||||
|   | ||||
| @@ -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, | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user