Refactor html templates
This commit entirely refactors the use of html templates. Instead of inheriting from a shared template, we insert the results into a base template.
This commit is contained in:
parent
6ede99d7c6
commit
d235ee4e5c
59 changed files with 869 additions and 777 deletions
29
internal/dis/component/server/templating/template.go
Normal file
29
internal/dis/component/server/templating/template.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package templating
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"html/template"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
)
|
||||
|
||||
//go:embed "src/footer.html"
|
||||
var footerHTML string
|
||||
var footerTemplate = template.Must(template.New("footer.html").Parse(footerHTML))
|
||||
|
||||
// GetCustomizable returns either a clone of dflt, or the overriden template with the same name.
|
||||
func (tpl *Templating) GetCustomizable(dflt *template.Template) *template.Template {
|
||||
name := dflt.Name()
|
||||
|
||||
custom, err := (func() (*template.Template, error) {
|
||||
data, err := environment.ReadFile(tpl.Environment, tpl.CustomAssetPath(name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return template.New(name).Parse(string(data))
|
||||
})()
|
||||
if err != nil {
|
||||
return template.Must(dflt.Clone())
|
||||
}
|
||||
return custom
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue