Add Lines method, remove path utils (Sprig pr)

pull/1666/head
Andrew Stuart 8 years ago
parent 5d58b7792c
commit 6760aa1588
No known key found for this signature in database
GPG Key ID: D409317C5B5ACD4D

@ -18,6 +18,7 @@ Helm provides access to files through the `.Files` object. Before we get going w
- [Glob patterns](#glob-patterns)
- [ConfigMap and Secrets utility functions](#configmap-and-secrets-utility-functions)
- [Secrets](#secrets)
- [Lines](#lines)
<!-- tocstop -->
@ -190,6 +191,17 @@ data:
bWVzc2FnZSA9IEhlbGxvIGZyb20gY29uZmlnIDEK
```
## Lines
Sometimes it is desireable to access each line of a file in your template. We
provide a convenient `Lines` method for this.
```yaml
data:
some-file.txt: {{ range .Files.Lines "foo/bar.txt" }}
{{ . }}{{ end }}
```
Currently, there is no way to pass files external to the chart during `helm install`. So if you are asking users to supply data, it must be loaded using `helm install -f` or `helm install --set`.
This discussion wraps up our dive into the tools and techniques for writing Helm templates. In the next section we will see how you can use one special file, `templates/NOTES.txt`, to send post-installation instructions to the users of your chart.

@ -18,6 +18,7 @@ package chartutil
import (
"encoding/base64"
"path"
"strings"
yaml "gopkg.in/yaml.v2"
@ -146,6 +147,15 @@ func (f Files) AsSecrets() string {
return ToYaml(m)
}
// Lines returns
func (f Files) Lines(string path) []string {
if f == nil || f[path] == nil {
return []string{}
}
return strings.Split(string(f[path]), "\n")
}
// ToYaml takes an interface, marshals it to yaml, and returns a string. It will
// always return a string, even on marshal error (empty string).
//

@ -71,11 +71,6 @@ func FuncMap() template.FuncMap {
// Add some extra functionality
extra := template.FuncMap{
"toYaml": chartutil.ToYaml,
"base": path.Base,
"dir": path.Dir,
"ext": path.Ext,
"isAbs": path.IsAbs,
"clean": path.Clean,
// This is a placeholder for the "include" function, which is
// late-bound to a template. By declaring it here, we preserve the

Loading…
Cancel
Save