dis: Rework styling and build procedure

This commit is contained in:
Tom Wiesing 2022-10-14 16:48:12 +02:00
parent 1e1d1a3cad
commit cdc7d69ad9
No known key found for this signature in database
51 changed files with 1251 additions and 339 deletions

29
pkg/resources/template.go Normal file
View file

@ -0,0 +1,29 @@
package resources
import (
"html/template"
"strings"
)
// MustParse parses a new "html/template" from the given value, and registers the given functions with it.
// When something goes wrong, calls panic()
func (resources *Resources) MustParse(value string) *template.Template {
return template.Must(resources.RegisterFuncs(template.New("")).Parse(value))
}
// RegisterFuncs registers two new template functions with t.
// "JS" and "CSS" that return the appropriate resources to insert into the template.
func (resources *Resources) RegisterFuncs(t *template.Template) *template.Template {
var builder strings.Builder
resources.WriteCSS(&builder)
css := template.HTML(builder.String())
builder.Reset()
resources.WriteJS(&builder)
js := template.HTML(builder.String())
return t.Funcs(template.FuncMap{
"JS": func() template.HTML { return js },
"CSS": func() template.HTML { return css },
})
}