From 834df9102bb71a8bcbda291d6504a6a45b357e78 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 20 Jan 2025 13:33:22 +0100 Subject: [PATCH] Refactor templates. --- templates/_base.tmpl | 1 + templates/_macros.tmpl | 42 ++++++++++++++++++++++++++++++++++++++++++ templates/booking.tmpl | 19 ++----------------- templates/index.tmpl | 25 ++----------------------- templates/raw.tmpl | 14 +------------- 5 files changed, 48 insertions(+), 53 deletions(-) create mode 100644 templates/_macros.tmpl diff --git a/templates/_base.tmpl b/templates/_base.tmpl index 8e6de41..2953be2 100644 --- a/templates/_base.tmpl +++ b/templates/_base.tmpl @@ -1,3 +1,4 @@ +{% import '_macros.tmpl' as macros %} diff --git a/templates/_macros.tmpl b/templates/_macros.tmpl new file mode 100644 index 0000000..4df4fc6 --- /dev/null +++ b/templates/_macros.tmpl @@ -0,0 +1,42 @@ +{% macro css_value_line() %} +td.amt { text-align: right } +td.amt, td.curr { font-family: monospace; font-size: 1.3em; } +td.curr { text-align: center; } +{% endmacro %} + +{% macro table_dat_lines(dat_lines, single, raw) %} + +{% for dat_line in dat_lines %} + {% if (not (raw or single)) and dat_line.type == "intro" and loop.index > 1 %} + + {% endif %} + + {% if not single %} + {% if dat_line.type == "intro" %} + + {% else %} + + {% endif %} + {% endif %} + {% if raw %} + {% if dat_line.type == "intro" %} + + {% else %} + + {% endif %} + {% else %} + {% if dat_line.type == "intro" %} + + {% elif dat_line.type == "value" %} + + + + {% else %} + + {% endif %} + + {% endif %} + +{% endfor %} +
 
#{{dat_line.raw_nbsp}}{{dat_line.raw_nbsp}}{{dat_line.code}}{{dat_line.booking_line.amt}}{{dat_line.booking_line.curr|truncate(4,true,"…")}}{{dat_line.booking_line.acc}}{{dat_line.code}}{{dat_line.comment}}
+{% endmacro %} diff --git a/templates/booking.tmpl b/templates/booking.tmpl index 1bfea62..86273b9 100644 --- a/templates/booking.tmpl +++ b/templates/booking.tmpl @@ -1,25 +1,10 @@ {% extends '_base.tmpl' %} {% block css %} -td.amt { text-align: right } -td.amt, td.curr { font-family: monospace; font-size: 1.3em; } -td.curr { text-align: center; } +{{ macros.css_value_line() }} {% endblock %} {% block content %} - -{% for l in dat_lines %} - - {% if l.type == "value" %} - - {% elif l.type == "intro" %} - - {% else %} - - {% endif %} - - -{% endfor %} -
{{l.booking_line.amt}}{{l.booking_line.curr|truncate(4,true,"…")}}{{l.booking_line.acc}}{{l.code}}{{l.code}}{{l.comment}}
+{{ macros.table_dat_lines(dat_lines, single=true, raw=false) }} {% endblock %} diff --git a/templates/index.tmpl b/templates/index.tmpl index 301b2d4..fc24e6e 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -1,33 +1,12 @@ {% extends '_base.tmpl' %} {% block css %} -td.amt { text-align: right } -td.amt, td.curr { font-family: monospace; font-size: 1.3em; } -td.curr { text-align: center; } +{{ macros.css_value_line() }} {% endblock %} {% block content %}

- -{% for l in dat_lines %} - {% if "intro" == l.type and loop.index > 1 %}{% endif %} - - {% if l.type == "intro" %} - - {% else %} - - {% endif %} - {% if l.type == "value" %} - - {% elif l.type == "intro" %} - - {% else %} - - {% endif %} - - -{% endfor %} -
 
#{{l.booking_line.amt}}{{l.booking_line.curr|truncate(4,true,"…")}}{{l.booking_line.acc}}{{l.code}}{{l.code}}{{l.comment}}
+{{ macros.table_dat_lines(dat_lines, single=false, raw=false) }} {% endblock %} diff --git a/templates/raw.tmpl b/templates/raw.tmpl index 59e951f..6851d93 100644 --- a/templates/raw.tmpl +++ b/templates/raw.tmpl @@ -5,18 +5,6 @@ table { font-family: monospace; } {% endblock %} {% block content %} - -{% for l in dat_lines %} - - {% if l.type == "intro" %} - - - {% else %} - - - {% endif %} - -{% endfor %} -
#{{l.raw_nbsp}}{{l.raw_nbsp}}
+{{ macros.table_dat_lines(dat_lines, single=false, raw=true) }} {% endblock %} -- 2.30.2