|
|
@ -37,7 +37,8 @@ type Engine struct {
|
|
|
|
FuncMap template.FuncMap
|
|
|
|
FuncMap template.FuncMap
|
|
|
|
// If strict is enabled, template rendering will fail if a template references
|
|
|
|
// If strict is enabled, template rendering will fail if a template references
|
|
|
|
// a value that was not passed in.
|
|
|
|
// a value that was not passed in.
|
|
|
|
Strict bool
|
|
|
|
Strict bool
|
|
|
|
|
|
|
|
CurrentTemplates map[string]renderable
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// New creates a new Go template Engine instance.
|
|
|
|
// New creates a new Go template Engine instance.
|
|
|
@ -65,7 +66,9 @@ func New() *Engine {
|
|
|
|
// - "include": This is late-bound in Engine.Render(). The version
|
|
|
|
// - "include": This is late-bound in Engine.Render(). The version
|
|
|
|
// included in the FuncMap is a placeholder.
|
|
|
|
// included in the FuncMap is a placeholder.
|
|
|
|
// - "required": This is late-bound in Engine.Render(). The version
|
|
|
|
// - "required": This is late-bound in Engine.Render(). The version
|
|
|
|
// included in thhe FuncMap is a placeholder.
|
|
|
|
// included in the FuncMap is a placeholder.
|
|
|
|
|
|
|
|
// - "tpl": This is late-bound in Engine.Render(). The version
|
|
|
|
|
|
|
|
// included in the FuncMap is a placeholder.
|
|
|
|
func FuncMap() template.FuncMap {
|
|
|
|
func FuncMap() template.FuncMap {
|
|
|
|
f := sprig.TxtFuncMap()
|
|
|
|
f := sprig.TxtFuncMap()
|
|
|
|
delete(f, "env")
|
|
|
|
delete(f, "env")
|
|
|
@ -84,6 +87,7 @@ func FuncMap() template.FuncMap {
|
|
|
|
// integrity of the linter.
|
|
|
|
// integrity of the linter.
|
|
|
|
"include": func(string, interface{}) string { return "not implemented" },
|
|
|
|
"include": func(string, interface{}) string { return "not implemented" },
|
|
|
|
"required": func(string, interface{}) interface{} { return "not implemented" },
|
|
|
|
"required": func(string, interface{}) interface{} { return "not implemented" },
|
|
|
|
|
|
|
|
"tpl": func(string, interface{}) interface{} { return "not implemented" },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for k, v := range extra {
|
|
|
|
for k, v := range extra {
|
|
|
@ -115,6 +119,7 @@ func FuncMap() template.FuncMap {
|
|
|
|
func (e *Engine) Render(chrt *chart.Chart, values chartutil.Values) (map[string]string, error) {
|
|
|
|
func (e *Engine) Render(chrt *chart.Chart, values chartutil.Values) (map[string]string, error) {
|
|
|
|
// Render the charts
|
|
|
|
// Render the charts
|
|
|
|
tmap := allTemplates(chrt, values)
|
|
|
|
tmap := allTemplates(chrt, values)
|
|
|
|
|
|
|
|
e.CurrentTemplates = tmap
|
|
|
|
return e.render(tmap)
|
|
|
|
return e.render(tmap)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -159,6 +164,23 @@ func (e *Engine) alterFuncMap(t *template.Template) template.FuncMap {
|
|
|
|
return val, nil
|
|
|
|
return val, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add the 'tpl' function here
|
|
|
|
|
|
|
|
funcMap["tpl"] = func(tpl string, vals chartutil.Values) (string, error) {
|
|
|
|
|
|
|
|
r := renderable{
|
|
|
|
|
|
|
|
tpl: tpl,
|
|
|
|
|
|
|
|
vals: vals,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
templates := map[string]renderable{}
|
|
|
|
|
|
|
|
templates["aaa_template"] = r
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result, err := e.render(templates)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return "", fmt.Errorf("Error during tpl function execution for %q: %s", tpl, err.Error())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result["aaa_template"], nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return funcMap
|
|
|
|
return funcMap
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -187,7 +209,7 @@ func (e *Engine) render(tpls map[string]renderable) (map[string]string, error) {
|
|
|
|
keys := sortTemplates(tpls)
|
|
|
|
keys := sortTemplates(tpls)
|
|
|
|
|
|
|
|
|
|
|
|
files := []string{}
|
|
|
|
files := []string{}
|
|
|
|
//for fname, r := range tpls {
|
|
|
|
|
|
|
|
for _, fname := range keys {
|
|
|
|
for _, fname := range keys {
|
|
|
|
r := tpls[fname]
|
|
|
|
r := tpls[fname]
|
|
|
|
t = t.New(fname).Funcs(funcMap)
|
|
|
|
t = t.New(fname).Funcs(funcMap)
|
|
|
@ -197,6 +219,17 @@ func (e *Engine) render(tpls map[string]renderable) (map[string]string, error) {
|
|
|
|
files = append(files, fname)
|
|
|
|
files = append(files, fname)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Adding the engine's currentTemplates to the template context
|
|
|
|
|
|
|
|
// so they can be referenced in the tpl function
|
|
|
|
|
|
|
|
for fname, r := range e.CurrentTemplates {
|
|
|
|
|
|
|
|
if t.Lookup(fname) == nil {
|
|
|
|
|
|
|
|
t = t.New(fname).Funcs(funcMap)
|
|
|
|
|
|
|
|
if _, err := t.Parse(r.tpl); err != nil {
|
|
|
|
|
|
|
|
return map[string]string{}, fmt.Errorf("parse error in %q: %s", fname, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rendered := make(map[string]string, len(files))
|
|
|
|
rendered := make(map[string]string, len(files))
|
|
|
|
var buf bytes.Buffer
|
|
|
|
var buf bytes.Buffer
|
|
|
|
for _, file := range files {
|
|
|
|
for _, file := range files {
|
|
|
|