Skip to content

Commit

Permalink
Merge pull request #804 from twpayne/allow-funcs-in-chezmoitemplates
Browse files Browse the repository at this point in the history
Allow all functions in .chezmoitemplates
  • Loading branch information
twpayne committed Jun 25, 2020
2 parents 2e2f815 + b611aea commit 2c97ca0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/chezmoi/targetstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ func (ts *TargetState) addTemplatesDir(fs vfs.FS, path string) error {
return err
}
name := strings.TrimPrefix(filepath.ToSlash(path), prefix)
tmpl, err := template.New(name).Parse(string(contents))
tmpl, err := template.New(name).Option(ts.TemplateOptions...).Funcs(ts.TemplateFuncs).Parse(string(contents))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/chezmoi/targetstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func TestTargetStatePopulate(t *testing.T) {
WithDestDir("/"),
WithSourceDir("/"),
WithTemplates(map[string]*template.Template{
"foo": template.Must(template.New("foo").Parse("bar")),
"foo": template.Must(template.New("foo").Option("missingkey=error").Parse("bar")),
}),
),
},
Expand Down
4 changes: 2 additions & 2 deletions testdata/scripts/executetemplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ chezmoi execute-template '{{ "output" }}'
stdout output

chezmoi execute-template '{{ template "partial" }}'
stdout partial-output
stdout 'hello world'

-- home/user/.local/share/chezmoi/.chezmoitemplates/partial --
partial-output
{{ cat "hello" "world" }}

0 comments on commit 2c97ca0

Please sign in to comment.