Browse Source

create debug macro

Julia Luna 2 years ago
parent
commit
e722ac8a90
Signed by: xenua
GPG Key ID: 6A0C04FA9A7D7582
  1. 47
      templates/macros.html

47
templates/macros.html

@ -0,0 +1,47 @@ @@ -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