docs: use nindent in documentation examples

Fixes #4890.

Signed-off-by: Geoff Baskwill <me@geoffbaskwill.ca>
pull/4905/head
Geoff Baskwill 7 years ago
parent 73dc31b248
commit b3e3bf6be0

@ -153,7 +153,7 @@ kind: ConfigMap
metadata:
name: conf
data:
{{ (.Files.Glob "foo/*").AsConfig | indent 2 }}
{{- (.Files.Glob "foo/*").AsConfig | nindent 2 }}
---
apiVersion: v1
kind: Secret
@ -161,7 +161,7 @@ metadata:
name: very-secret
type: Opaque
data:
{{ (.Files.Glob "bar/*").AsSecrets | indent 2 }}
{{- (.Files.Glob "bar/*").AsSecrets | nindent 2 }}
```
## Encoding

@ -223,7 +223,7 @@ Note that the indentation on `app_version` is wrong in both places. Why? Because
To work around this case, Helm provides an alternative to `template` that will import the contents of a template into the present pipeline where it can be passed along to other functions in the pipeline.
Here's the example above, corrected to use `indent` to indent the `mychart_app` template correctly:
Here's the example above, corrected to use `nindent` to indent the `mychart_app` template correctly:
```yaml
apiVersion: v1
@ -231,13 +231,13 @@ kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
labels:
{{ include "mychart.app" . | indent 4 }}
{{- include "mychart.app" . | nindent 4 }}
data:
myvalue: "Hello World"
{{- range $key, $val := .Values.favorite }}
{{ $key }}: {{ $val | quote }}
{{- end }}
{{ include "mychart.app" . | indent 2 }}
{{- include "mychart.app" . | nindent 2 }}
```
Now the produced YAML is correctly indented for each section:

@ -71,12 +71,16 @@ Go template pipelines.
To make it possible to include a template, and then perform an operation
on that template's output, Helm has a special `include` function:
```
{{ include "toYaml" $value | indent 2 }}
```gotpl
{{- include "toYaml" $value | nindent 2 }}
```
The above includes a template called `toYaml`, passes it `$value`, and
then passes the output of that template to the `indent` function.
then passes the output of that template to the `nindent` function. Using
the `{{- ... | nindent _n_ }}` pattern makes it easier to read the `include`
in context, because it chomps the whitespace to the left (including the
previous newline), then the `nindent` re-adds the newline and indents
the included content by the requested amount.
Because YAML ascribes significance to indentation levels and whitespace,
this is one great way to include snippets of code, but handle

Loading…
Cancel
Save