You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
869 B

package gohtml
import (
"context"
"fmt"
html "html/template"
"gitoa.ru/go-4devs/templating"
"gitoa.ru/go-4devs/templating/engine"
gohtml "gitoa.ru/go-4devs/templating/gohtml/engine"
"gitoa.ru/go-4devs/templating/loader"
)
const Name = gohtml.Name
var htm = gohtml.New()
func init() {
templating.AddEngine(htm)
}
// Loader set new loader. This function is not thread-safe.
func Loader(in loader.Loader) {
htm = htm.WithLoader(in)
}
func Must(template *html.Template, err error) {
MustRegister(html.Must(template, err))
}
func MustRegister(template *html.Template) {
if rerr := Register(template); rerr != nil {
panic(rerr)
}
}
func Register(template *html.Template) error {
if err := htm.Add(context.Background(), engine.NewTemplate(template.Name(), template.Execute)); err != nil {
return fmt.Errorf("gohtml loader:%w", err)
}
return nil
}