Refactor server and templates package
This commit is contained in:
parent
b6bf0a8900
commit
6ede99d7c6
105 changed files with 341 additions and 339 deletions
23
internal/dis/component/server/assets/templates.go
Normal file
23
internal/dis/component/server/assets/templates.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package assets
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"html/template"
|
||||
)
|
||||
|
||||
//go:embed "templates/*.html"
|
||||
var templates embed.FS
|
||||
|
||||
var (
|
||||
shared *template.Template = template.Must(template.ParseFS(templates, "templates/*.html"))
|
||||
)
|
||||
|
||||
// NewSharedTemplate creates a new template with the given name.
|
||||
// It will be able to make use of shared templates as well as functions.
|
||||
func NewSharedTemplate(name string) *template.Template {
|
||||
new := template.New(name)
|
||||
for _, template := range shared.Templates() {
|
||||
new.AddParseTree(template.Tree.Name, template.Tree.Copy())
|
||||
}
|
||||
return new
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue