Skip to content

Commit

Permalink
[bugfix] 50a1f7a:api.ApplyFile template function map is invalid due…
Browse files Browse the repository at this point in the history
… to not set.
  • Loading branch information
jellyterra committed Sep 2, 2024
1 parent 6e39964 commit 588f678
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion structure/v1_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ func (c *v1Api) Apply(templateName, templateKey string, data any) any {
func (c *v1Api) ApplyFile(std, path string, data map[string]any) string {
return c.Wrap(func() (_ string, err error) {

getFuncMap, ok := Versions[std]
if !ok {
return "", &UndefinedStdError{Std: std}
}

funcMap := getFuncMap(&Context{
AppliedTemplates: c.AppliedTemplates,
TemplateBase: filepath.Base(path),
Env: c.Env,
Root: c.Root,
Dest: c.Dest,
Data: data,
DataSet: nil,
Errors: c.Errors,
})

absolutePath := filepath.Join(c.Root.Path, path)

t, err := c.Env.GetTemplateFile(absolutePath, std)
Expand All @@ -82,7 +98,7 @@ func (c *v1Api) ApplyFile(std, path string, data map[string]any) string {

buf := bytes.NewBuffer(nil)

err = t.Execute(buf, data)
err = t.Funcs(funcMap).Execute(buf, data)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 588f678

Please sign in to comment.