Created
January 28, 2016 19:04
-
-
Save traverseda/4f43148331a469a9169c to your computer and use it in GitHub Desktop.
Render a json-tree recusrivly in jinja2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro keyValue(key,value) -%} | |
{# generic case, if key doesn't match a particular renderer #} | |
<div class="{{key}}"> | |
{{ router(value) }} | |
</div> | |
{%- endmacro %} | |
{% macro router(value)%} | |
{% if value is mapping %} | |
{% for key2,value2 in value.items() %} | |
{{ keyValue(key2,value2) }} | |
{% endfor %} | |
{% elif value is string %} | |
{{ value|markd }} | |
{% elif value is iterable %} | |
{{list(value)}} | |
{% endif %} | |
{% endmacro %} | |
{% macro list(data) %} | |
{% for item in data %} | |
{{ router(item) }} | |
{% endfor %} | |
{% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment