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

Set ordering #57

Closed
freeseacher opened this issue Oct 18, 2020 · 4 comments
Closed

Set ordering #57

freeseacher opened this issue Oct 18, 2020 · 4 comments

Comments

@freeseacher
Copy link
Contributor

freeseacher commented Oct 18, 2020

Hi. in #42, you have added helpers to make dicts and lists in runtime.
Recently I get some time to move to them instead of for loop.
But I probably got minor in my use-case but a fundamental problem in some other cases.

my template code is

{% set rules_set = createSet() %}
{%- for project in shard_config.projects -%}
  {%- if project.enabled_rules.team != "false" -%}
      {% set rule = printf("%s/teams/%s/%s", rules_prefix, project.team, rules_suffix )  %}
      {{ rules_set.Append(rule) }}
  {% endif %}
{%- endfor %}
{%- set rulesmap = createMap() %}
{{ rulesmap.Set("rule_files", rulesmap) }}
{{ rulesmap  | toYAML }}

Each time I render a file, I got a different ordering of lines.
I tied to switch to for with sorted according to https://github.com/flosch/pongo2/blob/master/template_tests/for.tpl

rule_files:
{% for line in rulesmap sorted %}
- {{ line }}
{{%endfor %}}

but this produces no lines at all. without sorted too :(

@freeseacher
Copy link
Contributor Author

It seems it is a more significant issue than it was from the first sight.
Files are continually changing due to different rendering.
But I've found a temporary solution for it.

rule_files:
% set rules = rulesmap | toJSON |parseJSON %}
{% for line in rules sorted %}
- {{ line }}
{{%endfor %}}

@HeavyHorst
Copy link
Owner

sorted works totally fine here:

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

rule_files:
{% set rules = map2 %}
{% for line in rules sorted %}
- {{ line }}
{% endfor %

Could you provide a simple example that doesn't work?

@HeavyHorst
Copy link
Owner

Ah ok, maps are working but sets not.
This is because the sets are from type map[interface{}]struct{} which isn't compatible with sorted.

@HeavyHorst
Copy link
Owner

Should be fixed in the new release: https://github.com/HeavyHorst/remco/releases/tag/v0.12.1

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