-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function similar to nindent but ignoring content's initial new line. #357
Comments
3 tasks
3 tasks
ksa-real
added a commit
to ksa-real/grafana-oncall
that referenced
this issue
Jun 22, 2023
- Enabling existing secrets for external MySQL and Redis - Tolerate existing secrets for bundled charts. - README.md: secrets handling explained. - Fixed multiple bugs where missing required field was replaced with default instead of failing. - PHONE_NOTIFICATIONS_LIMIT was on the wrong level: it was not set if existingSecret was true. Next are the cosmetic changes. They improve chart consistency, e.g. prevent generation of multiple new lines in certain cases: - Common approach to spaces trimming. This typically allows curly blocks and actual strings indentation and nice `nindent` usage: - Two curly blocks should not trim the same space. I.e. "{{ ... -}} {{- ... }}" shouldn't happen. - Template generates either single line or multiline string. In both cases, no new line appears on both sides of the output string. So we delete unnecessary new lines inside and at the end of string with "trim-to-left" (`{{-` ) and the leading new line using "trim-to-right" (`-}}`). Note that trimming both leading and trailing new line is not always easily possible: Masterminds/sprig#357 Example. ``` {{- define "mytemplate" -}} {{ if someBoolean -}} {{ .Value.some }} {{- else -}} some string {{- end }} {{- end }} ``` - `template` replaced with `include`. It is often recommended to use `include` by default, as it allows pipelining.
github-merge-queue bot
pushed a commit
to grafana/oncall
that referenced
this issue
Jun 23, 2023
- Enabling existing secrets for external MySQL and Redis - Tolerate existing secrets for bundled charts. - README.md: secrets handling explained. - Fixed multiple bugs where missing required field was replaced with default instead of failing. - PHONE_NOTIFICATIONS_LIMIT was on the wrong level: it was not set if existingSecret was true. Next are the cosmetic changes. They improve chart consistency, e.g. prevent generation of multiple new lines in certain cases: - Common approach to spaces trimming. This typically allows curly blocks and actual strings indentation and nice `nindent` usage: - Two curly blocks should not trim the same space. I.e. "{{ ... -}} {{- ... }}" shouldn't happen. - Template generates either single line or multiline string. In both cases, no new line appears on both sides of the output string. So we delete unnecessary new lines inside and at the end of string with "trim-to-left" (`{{-` ) and the leading new line using "trim-to-right" (`-}}`). Note that trimming both leading and trailing new line is not always easily possible: Masterminds/sprig#357 Example. ``` {{- define "mytemplate" -}} {{ if someBoolean -}} {{ .Value.some }} {{- else -}} some string {{- end }} {{- end }} ``` - `template` replaced with `include`. It is often recommended to use `include` by default, as it allows pipelining. ## Checklist - [ ] Tests updated - No tests for Helm chart - [X] Documentation added - [x] `CHANGELOG.md` updated Co-authored-by: Ildar Iskhakov <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The ask is to have a function that acts like
nindent
, but skips the content's leading new line. The same effect is if the function act s asindent
but doesn't indent the first line. This would allow templates to generate a leading new line that is useful in a lot of scenarios. The proposed name issnindent
orsindent
.Explanation
A common way of using templates:
This assumes that "my.multiline" template produces a string without leading and trailing new lines. Let the template generate a list of "items" (line per item), each guarded by some condition.
It is not possible to keep the two
if
blocks independent and keep no new lines around generated string for all possible values of booleancondition1
andcondition2
So, the best for template is to generate a new line character per line: leading or trailing. If using trailing, then
{{ include "sometemplate" . }}
would generate likely unnecessary extra new line.{{ include "sometemplate" . -}}
would in turn affect the next line indentation. So, a leading new line is the only option.Workarounds
The text was updated successfully, but these errors were encountered: