mirror of
https://github.com/Luzifer/korvike.git
synced 2024-12-29 23:51:16 +00:00
Knut Ahlers
e8a8b2f83f
Breaking changes: - Remove function `b64decode`, use `b64dec` - Remove function `b64encode`, use `b64enc` - Remove default from `env`, use `env "MYVAR" | default "..."` - Remove function `hash`, use `sha1sum` / `sha256sum` / `sha512sum` - Function `now` returns `time.Time`, use `now | date "[format]"` - Function `split` now has reversed parameters `split <sep> <str>` Signed-off-by: Knut Ahlers <knut@ahlers.me>
28 lines
682 B
Go
28 lines
682 B
Go
package functions
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"text/template"
|
|
)
|
|
|
|
var subTemplateVariables map[string]interface{}
|
|
|
|
// SetSubTemplateVariables sets variables to apply in `tplexec` function
|
|
func SetSubTemplateVariables(m map[string]interface{}) { subTemplateVariables = m }
|
|
|
|
func init() {
|
|
registerFunction("tplexec", func(rawTpl string) (string, error) {
|
|
tpl, err := template.New("in").Funcs(GetFunctionMap()).Parse(rawTpl)
|
|
if err != nil {
|
|
return "", fmt.Errorf("parse template: %w", err)
|
|
}
|
|
|
|
out := new(bytes.Buffer)
|
|
if err := tpl.Execute(out, subTemplateVariables); err != nil {
|
|
return "", fmt.Errorf("execute template: %w", err)
|
|
}
|
|
|
|
return out.String(), nil
|
|
})
|
|
}
|