{# This entry is evaluated on a translation-group by translation-group basis, and so far only receives the `translation_group` node. The intent here is to make it easier to insert additional text without needing to alter or understand the larger amount of HTML. See `sme` for an example of including the @reg attribute. #} {%- macro render_annotation(tg) -%} {# Render the annotation () node, unless it has a @fra_ref. #} {%- set annotations = tg.xpath('./re') %} {% set fra_ref = tg.xpath('./re/@fra_ref')|count > 0 %} {% if annotations|count > 0 and not fra_ref %} ({{ annotations[0].text }}) {% endif -%} {%- endmacro -%} {%- macro render_link(tg, t) -%} {# Render a link to the detailed page. One exception: if the lexicon annotation entry contains a @fra_ref attribute, then we make a reference link, inserting this attribute's value in as a parameter. om to personer --> hverandre: om to personer #} {% set text = t.text %} {% set link_target = '' %} {% set fra_ref = tg.xpath('./re/@fra_ref') %} {% set l_par = tg.xpath('./t/@l_par') %} {% set r_par = tg.xpath('./t/@r_par') %} {% if l_par|count > 0 %} {% set l_par_text = l_par[0] %} {% set if_l_par = true %} {% else %} {% set if_l_par = false %} {% endif %} {% if r_par|count > 0 %} {% set r_par_text = r_par[0] %} {% set if_r_par = true %} {% else %} {% set if_r_par = false %} {% endif %} {% if fra_ref|count > 0 %} {# If this is a reference link, then there is no data in the node, so the becomes the link text. #} {% set annotations = tg.xpath('./re') %} {% set reference = fra_ref|join('') %} {% set text = annotations[0].text %} {% else %} {% set reference = false %} {% endif %} {%- if reference %} {% if if_l_par or if_r_par %} {% if if_l_par and if_r_par %} ({{l_par_text}}) {{- text -}} ({{r_par_text}}) {% else %} {% if if_l_par and not if_r_par %} ({{l_par_text}}) {{- text -}} {% else %} {% if not if_l_par and if_r_par %} {{- text -}} ({{r_par_text}}) {% endif %} {% endif %} {% endif %} {% else %} {{- text -}} → {% endif %} {%- else %} {# NB: swap from and to for these links since these are definitions. #} {% if if_l_par or if_r_par %} {% if if_l_par and if_r_par %} ({{l_par_text}}) {{- text -}} ({{r_par_text}}) {% else %} {% if if_l_par and not if_r_par %} ({{l_par_text}}) {{- text -}} {% else %} {% if not if_l_par and if_r_par %} {{- text -}} ({{r_par_text}}) {% endif %} {% endif %} {% endif %} {% else %} {{- text -}} {% endif %} {%- endif %} {%- endmacro -%} {%- macro render_tg(tg) -%} {# Render all the texts as individual links, followed by a potential annotation. #} {% for t in tg.xpath('./t') %} {{ render_link(tg, t) -}}{% if not loop.last %}, {% endif %} {% endfor %} {{- render_annotation(tg) -}} {%- endmacro -%} {%- if translation_group -%} {{ render_tg(translation_group) }} {%- endif -%} {# vim: set ts=4 sw=4 tw=72 syntax=htmljinja : #}