dis: Rework styling and build procedure
This commit is contained in:
parent
1e1d1a3cad
commit
cdc7d69ad9
51 changed files with 1251 additions and 339 deletions
29
pkg/resources/template.go
Normal file
29
pkg/resources/template.go
Normal 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 },
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue