Skip to content

Commit

Permalink
added some functions from helm (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-santiago authored and belitre committed Feb 12, 2019
1 parent e0d1dd9 commit a3c7b2b
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 49 deletions.
144 changes: 107 additions & 37 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/Masterminds/sprig"
version = "2.16.0"

[[constraint]]
name = "github.com/ghodss/yaml"
version = "1.0.0"
Expand All @@ -41,10 +36,6 @@
name = "github.com/stretchr/testify"
version = "1.2.1"

[[constraint]]
name = "k8s.io/helm"
version = "2.8.2"

[prune]
go-tests = true
unused-packages = true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Inspired by [Helm](https://github.com/kubernetes/helm)

Started as a fork from [github.com/tsg/gotpl](https://github.com/tsg/gotpl) but this project looks abandoned

Added some things from [Helm](https://github.com/kubernetes/helm), like the way they read values.
Added some things from [Helm](https://github.com/kubernetes/helm), like the way they read values, and some functions for the templates.

And some improvements by myself :)

Expand Down
2 changes: 1 addition & 1 deletion commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// Version should be updated each time there is a new release
var (
Version = "v0.4"
Version = "v0.5"
GitCommit = ""
)

Expand Down
22 changes: 21 additions & 1 deletion tpl/tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,33 @@ import (

"github.com/Masterminds/sprig"
"github.com/ghodss/yaml"
"k8s.io/helm/pkg/chartutil"
"k8s.io/helm/pkg/strvals"
)

func getFunctions() template.FuncMap {
f := sprig.TxtFuncMap()

// from Helm!
extra := template.FuncMap{
"toToml": chartutil.ToToml,
"toYaml": chartutil.ToYaml,
"fromYaml": chartutil.FromYaml,
"toJson": chartutil.ToJson,
"fromJson": chartutil.FromJson,
}

for k, v := range extra {
f[k] = v
}

return f
}

func executeTemplates(values map[string]interface{}, tplFiles []string, isStrict bool) (string, error) {
buf := bytes.NewBuffer(nil)
for _, f := range tplFiles {
tpl := template.New(path.Base(f)).Funcs(sprig.TxtFuncMap())
tpl := template.New(path.Base(f)).Funcs(getFunctions())
if isStrict {
tpl.Option("missingkey=error")
}
Expand Down

0 comments on commit a3c7b2b

Please sign in to comment.