Comments (10)
from gomplate.
Ok - I've logged #165 to track the indent
enhancement that's come out of this.
For the indentfirst
functionality, you can pipe the output to trimSpace
to achieve the same effect:
$ gomplate -i '{{ "foo\nbar\nbaz" | indent " " | trimSpace }}'
foo
bar
baz
from gomplate.
@glensc @hairyhenderson You can replicate the behavior of the Helm nindent
function in gomplate
by printing "\n"
before your template:
metadata:
labels:
{{- print "\n" (.data.my_labels | toYAML | trimSpace | indent 4) }}
This sort of pattern lets you remove leading newlines with{{-
, so you can indent the template for visual clarity.
Note, the trimSpace
is there to remove the strange dangling newline that toYAML
seems to create.
from gomplate.
@estahn for this, you want the indent
function - I actually wrote that specifically for dealing with YAML indentation 😉
from gomplate.
@hairyhenderson Well, that would result in pretty ugly templates, e.g.
spec:
schedule: "{{ .schedule }}"
concurrencyPolicy: Forbid
jobTemplate:
spec:
activeDeadlineSeconds: 30
template:
spec:
restartPolicy: Never
containers:
- name: app
image: "123"
args:
{{ .args | toYAML | indent(" ") }}
from gomplate.
Yup, I agree, that's not ideal. But there's no way for gomplate
to know about text outside of the {{
/}}
delimiters.
In your specific case, since YAML is a JSON superset, it's probably best to take the approach you seem to have explored in #163 and render that particular value as JSON.
from gomplate.
Would it be possible to adjust indent
to something what jinja provides?
http://jinja.pocoo.org/docs/2.9/templates/#indent
indent(s, width=4, indentfirst=False)
Return a copy of the passed string, each line indented by 4 spaces. The first line is not indented. If you want to change the number of spaces or indent the first line too you can pass additional parameters to the filter:
{{ mytext|indent(2, true) }}
indent by two spaces and indent the first line too.
from gomplate.
@estahn Just to be clear about what you're asking - are you looking for indent
to be callable like this?
$ gomplate -i '{{ "foo" | indent 4 }}'
foo
That seems reasonable. Because indent
already exists, I can't change the existing functionality, but what I can do is overload it so that you can provide an optional width parameter.
Is the indentfirst
option of jinja's indent
useful to you? If I were to implement that it'd probably be as a separate function (maybe strings.IndentAfter
or something like that).
from gomplate.
@hairyhenderson It is probably useful otherwise you will need to place the placeholder always at the beginning of the line.
Example:
spec:
schedule: "{{ .schedule }}"
concurrencyPolicy: Forbid
jobTemplate:
spec:
activeDeadlineSeconds: 30
template:
spec:
restartPolicy: Never
containers:
- name: app
image: "123"
args:
{{ .args | toYAML | indent(16) }}
vs
spec:
schedule: "{{ .schedule }}"
concurrencyPolicy: Forbid
jobTemplate:
spec:
activeDeadlineSeconds: 30
template:
spec:
restartPolicy: Never
containers:
- name: app
image: "123"
args:
{{ .args | toYAML | indent(16) }}
from gomplate.
The need for trimSpace
problem is still there:
i.e for yaml formating typically the indent should be omitted so the function itself can be kept indented.
or I'm missing something?
I'm trying to load .env
file for helm values file:
$ cat .env
APP_ENV=production
APP_DEBUG=false
APP_KEY=SomeRandomString
APP_URL=http://localhost
$ cat values.yml
config:
{{ (ds "data") | data.ToYAML | strings.Indent 1 " " | trimSpace }}
config-example:
{{ (ds "data") | data.ToYAML | strings.Indent 1 " " }}
$ gomplate -d data=file://`pwd`/.env?type=application/x-env -f values.yml
config:
APP_DEBUG: "false"
APP_ENV: production
APP_KEY: SomeRandomString
APP_URL: http://localhost
config-example:
APP_DEBUG: "false"
APP_ENV: production
APP_KEY: SomeRandomString
APP_URL: http://localhost
in helm, there's extra function nindent doing that:
from gomplate.
Related Issues (20)
- [Feature]: integrate expr-lang HOT 4
- [Feature] Handle with not existing keys HOT 4
- Question / Feature request - `coll.Omit` and lists/slices HOT 2
- N/A
- Provide a "cli command" datasource to allow custom integration with any external data source HOT 3
- security: CVE-2023-49569 - go-git/v5 HOT 2
- Gomplate not preserving AWS-specific custom YAML tags on merge HOT 3
- Specifying templates in the `.gomplate.yaml` causes no output to be rendered HOT 6
- New feature: GraphQL datasource HOT 3
- plugin args example does not work HOT 4
- Issue Running Gomplate with `go run` due to Module Path Mismatch HOT 2
- Using Gomplate as a library HOT 2
- Evaluate implementation of HCL support HOT 3
- Allow empty values returned by JSONPath HOT 1
- Processing mixed outputs between custom path & output-dir HOT 1
- Cannot install in GitHub Actions using go install HOT 8
- `file.Write` doesn't respect outputDir HOT 5
- gomplate produces no result and no error HOT 1
- Need to finalize gomplate.Renderer and related types before v4.0.0 HOT 2
- Tests failing on 32-bit builds due to unaligned struct in dependency HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gomplate.