feat(xtemplate,text): wrapper for html/template.Template struct
This commit is contained in:
89
xtemplate/html.go
Normal file
89
xtemplate/html.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package xtemplate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
"io"
|
||||||
|
"io/fs"
|
||||||
|
"text/template/parse"
|
||||||
|
)
|
||||||
|
|
||||||
|
type htmlTemplate struct {
|
||||||
|
html *template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Template = (*htmlTemplate)(nil)
|
||||||
|
|
||||||
|
func (t *htmlTemplate) AddParseTree(name string, tree *parse.Tree) (Template, error) {
|
||||||
|
temp, err := t.html.AddParseTree(name, tree)
|
||||||
|
return &htmlTemplate{temp}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) Clone() (Template, error) {
|
||||||
|
temp, err := t.html.Clone()
|
||||||
|
return &htmlTemplate{temp}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) Delims(left, right string) Template {
|
||||||
|
return &htmlTemplate{t.html.Delims(left, right)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) DefinedTemplates() string {
|
||||||
|
return t.html.DefinedTemplates()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) Execute(wr io.Writer, data any) error {
|
||||||
|
return t.html.Execute(wr, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) ExecuteTemplate(wr io.Writer, name string, data any) error {
|
||||||
|
return t.html.ExecuteTemplate(wr, name, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) Funcs(funcMap template.FuncMap) Template {
|
||||||
|
return &htmlTemplate{t.html.Funcs(funcMap)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) Lookup(name string) Template {
|
||||||
|
return &htmlTemplate{t.html.Lookup(name)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) Name() string {
|
||||||
|
return t.html.Name()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) New(name string) Template {
|
||||||
|
return &htmlTemplate{t.html.New(name)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) Option(opt ...string) Template {
|
||||||
|
return &htmlTemplate{t.html.Option(opt...)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) Parse(text string) (Template, error) {
|
||||||
|
temp, err := t.html.Parse(text)
|
||||||
|
return &htmlTemplate{temp}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) ParseFS(fs fs.FS, patterns ...string) (Template, error) {
|
||||||
|
temp, err := t.html.ParseFS(fs, patterns...)
|
||||||
|
return &htmlTemplate{temp}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) ParseFiles(filenames ...string) (Template, error) {
|
||||||
|
temp, err := t.html.ParseFiles(filenames...)
|
||||||
|
return &htmlTemplate{temp}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) ParseGlob(pattern string) (Template, error) {
|
||||||
|
temp, err := t.html.ParseGlob(pattern)
|
||||||
|
return &htmlTemplate{temp}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *htmlTemplate) Templates() []Template {
|
||||||
|
htmltemps := t.html.Templates()
|
||||||
|
temps := make([]Template, len(htmltemps))
|
||||||
|
for i := range len(temps) {
|
||||||
|
temps[i] = &htmlTemplate{htmltemps[i]}
|
||||||
|
}
|
||||||
|
return temps
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user