postfix-formula/postfix/files/mapping.j2
2019-04-09 20:06:16 +02:00

28 lines
899 B
Django/Jinja

# Managed by config management
{#- Some files (mainly the aliases one) require key and values
to be separated with a colon. For this `colon: True` should
be passed to the template #}
{%- if colon is not defined %}
{%- set colon = False %}
{%- endif %}
{%- macro format_value(key, value) %}
{#- Some settings, like virtual_alias_maps can take multiple values. Handle this case. -#}
{%- if value is iterable and value is not string -%}
{{ key }}{% if colon %}:{% endif %} {{ value|join(", ") }}
{%- else -%}
{{ key }}{% if colon %}:{% endif %} {{ value }}
{%- endif -%}
{%- endmacro %}
{%- if data is mapping %}
{% for key, value in data.items() %}
{{ format_value(key, value) }}
{%- endfor -%}
{%- else %}
{#- Some settings need order, handle OrderedDict #}
{% for item in data %}
{%- set key, value = item.popitem() %}
{{ format_value(key, value) }}
{%- endfor -%}
{%- endif %}