php-formula/php/macro.jinja
sticky-note f1b71d00ae feat(ng): promote NG formula
BREAKING CHANGES: users must adapt their pillar. See `docs.REAME.rst`
2019-08-20 13:01:49 +11:00

30 lines
945 B
Django/Jinja

# -*- coding: utf-8 -*-
# vim: ft=jinja
{# Returns a generic block of values suitable for inclusion in most states #}
{% macro sls_block(dict, ind=4) %}
{% for key, value in dict.items() %}
{{ '-'|indent(ind, True) }} {{ key }}: {{ value|json() }}
{% endfor %}
{% endmacro %}
{# Serializes dicts into sequenced data #}
{%- macro serialize(data) -%}
{%- if data is mapping -%}
{%- set ret = [] -%}
{%- for key, value in data.items() -%}
{%- set value = serialize(value)|load_json() -%}
{%- do ret.append({key: value}) -%}
{%- endfor -%}
{%- elif data is iterable and data is not string -%}
{%- set ret = [] -%}
{%- for value in data -%}
{%- set value = serialize(value)|load_json() -%}
{%- do ret.append(value) -%}
{%- endfor -%}
{%- else -%}
{% set ret = data %}
{%- endif -%}
{{ ret|json() }}
{%- endmacro -%}