Skip to content

Commit

Permalink
fix(render):musttemplate adds funcs to template before parsing (#293)
Browse files Browse the repository at this point in the history
Co-authored-by: Logan Jones <ljones@miletwo.us>
  • Loading branch information
LJ-Software and Logan Jones committed Jul 16, 2023
1 parent 9a8b8c2 commit 24032ab
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions render/engine.go
Expand Up @@ -23,9 +23,7 @@ const (
ModPage = "page"
)

var (
pat = regexp.MustCompile(`(__f__")|("__f__)|(__f__)`)
)
var pat = regexp.MustCompile(`(__f__")|("__f__)|(__f__)`)

type pageRender struct {
c interface{}
Expand Down Expand Up @@ -105,12 +103,13 @@ func isSet(name string, data interface{}) bool {

// MustTemplate creates a new template with the given name and parsed contents.
func MustTemplate(name string, contents []string) *template.Template {
tpl := template.Must(template.New(name).Parse(contents[0])).Funcs(template.FuncMap{
tpl := template.New(name).Funcs(template.FuncMap{
"safeJS": func(s interface{}) template.JS {
return template.JS(fmt.Sprint(s))
},
"isSet": isSet,
})
tpl = template.Must(tpl.Parse(contents[0]))

for _, cont := range contents[1:] {
tpl = template.Must(tpl.Parse(cont))
Expand Down

0 comments on commit 24032ab

Please sign in to comment.