You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is almost it, but it doesn't unnest things that are lists in the way we would expect:
{% macro dict_to_yaml(my_dict, indent=0, result="") %}
{% set ns=namespace(result=result) %}
{% for key, value in my_dict.items() %}
{% set ns.result= ns.result ~ " " * indent ~ key %}
{% if value is mapping %} {# if it's a dictionary, recurse #}
{% set ns.result=dict_to_yaml(value, indent + 2, ns.result ~ ":\n") %}
{% elif value is iterable and value is not string %} {# janky way to check for a list #}
{% set ns.result = ns.result ~ ":\n" %}
{% for item in value %}
{% set ns.result = ns.result ~ " " * indent ~ "- " ~ item ~ "\n" %}
{% endfor %}
{% else %}
{% set ns.result = ns.result ~ ": " ~ value ~ "\n" %}
{% endif %}
{% endfor %}
{{ return(ns.result) }}
{% endmacro %}
The text was updated successfully, but these errors were encountered:
This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.
Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers.
This will make generating yaml so much cleaner!
This is almost it, but it doesn't unnest things that are lists in the way we would expect:
The text was updated successfully, but these errors were encountered: