forked from saltstack-formulas/php-formula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacro.jinja
27 lines (25 loc) · 898 Bytes
/
macro.jinja
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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 -%}