From a93d823a56252d46bb4d00042815a22c4d880dd4 Mon Sep 17 00:00:00 2001 From: xenua Date: Sun, 3 Jul 2022 18:22:36 +0200 Subject: [PATCH] create debug macro --- templates/macros.html | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 templates/macros.html diff --git a/templates/macros.html b/templates/macros.html new file mode 100644 index 0000000..cb02c69 --- /dev/null +++ b/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 %} + + {% if label %}{{ label }}: {% endif %}{{ type }} + + {% set rdepth = recurse - 1 %} +
+ {% if type == "dict" %} + {% for k, v in thing %} + {% if v is iterable and recurse %} + {{ k }}: {{ self::debug(thing=v, recurse=rdepth) }} + {% else %} + {{ k }}: {{ v }}
+ {% endif %} + {% endfor %} + {% elif type == "list" %} + {% for v in thing %} + {% if v is iterable and recurse %} + {{ self::debug(thing=v, recurse=rdepth) }} + {% else %} + {{ v }}
+ {% endif %} + {% endfor %} + {% else %} + {{ thing }} + {% endif %} +
+{% endmacro %} \ No newline at end of file