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) - [Glob patterns](#glob-patterns)
- [ConfigMap and Secrets utility functions](#configmap-and-secrets-utility-functions) - [ConfigMap and Secrets utility functions](#configmap-and-secrets-utility-functions)
- [Secrets](#secrets) - [Secrets](#secrets)
- [Lines](#lines)
<!-- tocstop --> <!-- tocstop -->
@ -190,6 +191,17 @@ data:
bWVzc2FnZSA9IEhlbGxvIGZyb20gY29uZmlnIDEK 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`. 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. 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 ( import (
"encoding/base64" "encoding/base64"
"path" "path"
"strings"
yaml "gopkg.in/yaml.v2" yaml "gopkg.in/yaml.v2"
@ -146,6 +147,15 @@ func (f Files) AsSecrets() string {
return ToYaml(m) 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 // ToYaml takes an interface, marshals it to yaml, and returns a string. It will
// always return a string, even on marshal error (empty string). // always return a string, even on marshal error (empty string).
// //

@ -71,11 +71,6 @@ func FuncMap() template.FuncMap {
// Add some extra functionality // Add some extra functionality
extra := template.FuncMap{ extra := template.FuncMap{
"toYaml": chartutil.ToYaml, "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 // This is a placeholder for the "include" function, which is
// late-bound to a template. By declaring it here, we preserve the // late-bound to a template. By declaring it here, we preserve the

Loading…
Cancel
Save