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: metadata:
name: conf name: conf
data: data:
{{ (.Files.Glob "foo/*").AsConfig | indent 2 }} {{- (.Files.Glob "foo/*").AsConfig | nindent 2 }}
--- ---
apiVersion: v1 apiVersion: v1
kind: Secret kind: Secret
@ -161,7 +161,7 @@ metadata:
name: very-secret name: very-secret
type: Opaque type: Opaque
data: data:
{{ (.Files.Glob "bar/*").AsSecrets | indent 2 }} {{- (.Files.Glob "bar/*").AsSecrets | nindent 2 }}
``` ```
## Encoding ## 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. 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 ```yaml
apiVersion: v1 apiVersion: v1
@ -231,13 +231,13 @@ kind: ConfigMap
metadata: metadata:
name: {{ .Release.Name }}-configmap name: {{ .Release.Name }}-configmap
labels: labels:
{{ include "mychart.app" . | indent 4 }} {{- include "mychart.app" . | nindent 4 }}
data: data:
myvalue: "Hello World" myvalue: "Hello World"
{{- range $key, $val := .Values.favorite }} {{- range $key, $val := .Values.favorite }}
{{ $key }}: {{ $val | quote }} {{ $key }}: {{ $val | quote }}
{{- end }} {{- end }}
{{ include "mychart.app" . | indent 2 }} {{- include "mychart.app" . | nindent 2 }}
``` ```
Now the produced YAML is correctly indented for each section: 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 To make it possible to include a template, and then perform an operation
on that template's output, Helm has a special `include` function: on that template's output, Helm has a special `include` function:
``` ```gotpl
{{ include "toYaml" $value | indent 2 }} {{- include "toYaml" $value | nindent 2 }}
``` ```
The above includes a template called `toYaml`, passes it `$value`, and 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, Because YAML ascribes significance to indentation levels and whitespace,
this is one great way to include snippets of code, but handle this is one great way to include snippets of code, but handle

Loading…
Cancel
Save