Browse Source

create debug macro

main
xenua 3 years ago
parent
commit
a93d823a56
  1. 47
      templates/macros.html

47
templates/macros.html

@ -0,0 +1,47 @@
{% macro typeof(thing) %}
{% if thing is iterable %}
{% if thing is object %}
dict
{% else %}
list
{% endif %}
{% else %}
{% if thing is string %}
str
{% elif thing is number %}
num
{% else %}
other
{% endif %}
{% endif %}
{% endmacro typeof %}
{% macro debug(thing, label="", recurse=0) %}
{% set type = self::typeof(thing=thing) | trim %}
<span>{% if label %}{{ label }}: {% endif %}<em>{{ type }}</em></span>
{% set rdepth = recurse - 1 %}
<div class="debug">
{% if type == "dict" %}
{% for k, v in thing %}
{% if v is iterable and recurse %}
<span>{{ k }}: {{ self::debug(thing=v, recurse=rdepth) }}</span>
{% else %}
<span>{{ k }}: {{ v }}</span><br>
{% endif %}
{% endfor %}
{% elif type == "list" %}
{% for v in thing %}
{% if v is iterable and recurse %}
<span>{{ self::debug(thing=v, recurse=rdepth) }}</span>
{% else %}
<span>{{ v }}</span><br>
{% endif %}
{% endfor %}
{% else %}
{{ thing }}
{% endif %}
</div>
{% endmacro %}
Loading…
Cancel
Save