Skip to content
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

Render yaml config with toYAML #42

Closed
freeseacher opened this issue Jul 3, 2020 · 5 comments
Closed

Render yaml config with toYAML #42

freeseacher opened this issue Jul 3, 2020 · 5 comments

Comments

@freeseacher
Copy link
Contributor

Hi.
I want to render template like config | toYAML but i have to create config in runtime
That is a set that should be compiled from several for and lots of if.
How should i do it with pongo2 and remco ?

As i see there are no simple way how to create empty set and append values to it.
Any ideas ?

@HeavyHorst
Copy link
Owner

I experimented a little bit and got something like this working:

{% set map = createMap() %}
{{  map.Set("Moin", "Hallo") }}
{{  map.Set("Test", 100) }}
{{ map.Map() | toYAML }}

{% set map2 = createMap() %}
{{  map2.Set("Moin", "Hallo") }}
{{  map2.Set("Test", 100) }}
{{  map2.Set("anotherMap", map.Map()) }}
{{ map2.Map() | toYAML }}

Output:

Moin: Hallo
Test: 100





Moin: Hallo
Test: 100
anotherMap:
  Moin: Hallo
  Test: 100

would that work for you?
If so, I would still have to write tests/documentation and would push the code tonight.

@freeseacher
Copy link
Contributor Author

This looks promising.
my final idea is to get list without dupes

@HeavyHorst
Copy link
Owner

Could you create a complete syntax example + the desired output?

@freeseacher
Copy link
Contributor Author

Template should be like...

{% set rule_files = createMap() %}
{% for project in shard_config.projects %}
  {% if project.enabled_rules.team != "false" %}
    {{ rule_files.append({{prefix}}/team/{{ project.team }}/*.yml) }}
  {% endif %}
  {% if project.enabled_rules.product != "false" %}
    {{ rule_files.append({{prefix}}/products/{{ project.product }}/*.yml }}
  {% endif %}
  ....
{% endfor %}
{% for rules in shard_config.shared_rules %}
  {{ rule_files.append({{prefix}}/shared/technology/{{rules}}) }}
{% endfor %}
....

{{ rule_files | toYAML }}

output should be like

rule_files:
- ...
- ...
- ...

@HeavyHorst
Copy link
Owner

I create a map and a set Data Type (see https://github.com/HeavyHorst/remco/blob/master/docs/content/template/template-functions.md):

map:

{% set map = createMap() %}
{{  map.Set("Moin", "Hallo2") }}
{{  map.Set("Test", 105) }}
{{ map | toYAML }}

{% set map2 = createMap() %}
{{  map2.Set("Moin", "Hallo") }}
{{  map2.Set("Test", 300) }}
{{  map2.Set("anotherMap", map) }}
{{ map2 | toYAML }}

Set:

{% set s = createSet() %}
{{  s.Append("Moin") }}
{{  s.Append("Moin") }}
{{  s.Append("Hallo") }}
{{  s.Append(1) }}
{{ s | toYAML }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants