mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-18 19:01:50 +02:00
chore: tidy up pkgs (#636)
for readability and towards potentially making helmfile usable as a go library
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package tmpl
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/Masterminds/sprig"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
func (c *Context) stringTemplate() *template.Template {
|
||||
funcMap := sprig.TxtFuncMap()
|
||||
for name, f := range c.createFuncMap() {
|
||||
funcMap[name] = f
|
||||
}
|
||||
tmpl := template.New("stringTemplate").Funcs(funcMap)
|
||||
if c.preRender {
|
||||
tmpl.Option("missingkey=zero")
|
||||
} else {
|
||||
tmpl.Option("missingkey=error")
|
||||
}
|
||||
return tmpl
|
||||
}
|
||||
|
||||
func (c *Context) RenderTemplateToBuffer(s string, data ...interface{}) (*bytes.Buffer, error) {
|
||||
var t, parseErr = c.stringTemplate().Parse(s)
|
||||
if parseErr != nil {
|
||||
return nil, parseErr
|
||||
}
|
||||
|
||||
var tplString bytes.Buffer
|
||||
var d interface{}
|
||||
if len(data) > 0 {
|
||||
d = data[0]
|
||||
}
|
||||
var execErr = t.Execute(&tplString, d)
|
||||
|
||||
if execErr != nil {
|
||||
return &tplString, execErr
|
||||
}
|
||||
|
||||
return &tplString, nil
|
||||
}
|
||||
Reference in New Issue
Block a user