Skip to content

Commit a3c7b2b

Browse files
miguel-santiagobelitre
authored andcommitted
added some functions from helm (#10)
1 parent e0d1dd9 commit a3c7b2b

5 files changed

Lines changed: 130 additions & 49 deletions

File tree

Gopkg.lock

Lines changed: 107 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424
# go-tests = true
2525
# unused-packages = true
2626

27-
28-
[[constraint]]
29-
name = "github.com/Masterminds/sprig"
30-
version = "2.16.0"
31-
3227
[[constraint]]
3328
name = "github.com/ghodss/yaml"
3429
version = "1.0.0"
@@ -41,10 +36,6 @@
4136
name = "github.com/stretchr/testify"
4237
version = "1.2.1"
4338

44-
[[constraint]]
45-
name = "k8s.io/helm"
46-
version = "2.8.2"
47-
4839
[prune]
4940
go-tests = true
5041
unused-packages = true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Inspired by [Helm](https://github.com/kubernetes/helm)
99

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

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

1414
And some improvements by myself :)
1515

commands/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
// Version should be updated each time there is a new release
1010
var (
11-
Version = "v0.4"
11+
Version = "v0.5"
1212
GitCommit = ""
1313
)
1414

tpl/tpl.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,33 @@ import (
1111

1212
"github.com/Masterminds/sprig"
1313
"github.com/ghodss/yaml"
14+
"k8s.io/helm/pkg/chartutil"
1415
"k8s.io/helm/pkg/strvals"
1516
)
1617

18+
func getFunctions() template.FuncMap {
19+
f := sprig.TxtFuncMap()
20+
21+
// from Helm!
22+
extra := template.FuncMap{
23+
"toToml": chartutil.ToToml,
24+
"toYaml": chartutil.ToYaml,
25+
"fromYaml": chartutil.FromYaml,
26+
"toJson": chartutil.ToJson,
27+
"fromJson": chartutil.FromJson,
28+
}
29+
30+
for k, v := range extra {
31+
f[k] = v
32+
}
33+
34+
return f
35+
}
36+
1737
func executeTemplates(values map[string]interface{}, tplFiles []string, isStrict bool) (string, error) {
1838
buf := bytes.NewBuffer(nil)
1939
for _, f := range tplFiles {
20-
tpl := template.New(path.Base(f)).Funcs(sprig.TxtFuncMap())
40+
tpl := template.New(path.Base(f)).Funcs(getFunctions())
2141
if isStrict {
2242
tpl.Option("missingkey=error")
2343
}

0 commit comments

Comments
 (0)