fix(pkg/engine): allow to override all functions

Signed-off-by: Stepan Paksashvili <stepan.paksashvili@flant.com>
pull/30734/head
Stepan Paksashvili 5 months ago
parent 5c2f89307d
commit b54349d9b2

@ -196,11 +196,6 @@ func (e Engine) initFunMap(t *template.Template) {
funcMap := funcMap()
includedNames := make(map[string]int)
// Set custom template funcs
for k, v := range e.CustomTemplateFuncs {
funcMap[k] = v
}
// Add the template-rendering functions here so we can close over t.
funcMap["include"] = includeFun(t, includedNames)
funcMap["tpl"] = tplFun(t, includedNames, e.Strict)
@ -251,6 +246,11 @@ func (e Engine) initFunMap(t *template.Template) {
}
}
// Set custom template funcs
for k, v := range e.CustomTemplateFuncs {
funcMap[k] = v
}
t.Funcs(funcMap)
}

@ -1302,7 +1302,7 @@ func TestRenderTplMissingKeyString(t *testing.T) {
}
func TestRenderCustomTemplateFuncs(t *testing.T) {
// Create a chart with a single template that uses a custom function "exclaim"
// Create a chart with two templates that use custom functions
c := &chart.Chart{
Metadata: &chart.Metadata{Name: "CustomFunc"},
Templates: []*chart.File{
@ -1326,7 +1326,7 @@ func TestRenderCustomTemplateFuncs(t *testing.T) {
},
}
// Define a custom template function "exclaim" that appends "!!!" to a string.
// Define a custom template function "exclaim" that appends "!!!" to a string and override "upper" function
customFuncs := template.FuncMap{
"exclaim": func(input string) string {
return input + "!!!"

Loading…
Cancel
Save