{# This entry is evaluated on a translation-group by translation-group basis, and so far only receives the `translation_group` node. NB: There is one override here, which is to deal with the nodes. For now these shouldn't be links, but we might change the link target to the grammar at some point. see: render_link #} {%- macro render_annotation(tg) -%} {# Render the annotation () node, unless it has a @fra_ref. #} {%- set annotations = tg.xpath('./re') %} {%- set contains_grammar_link = tg.xpath('./t/@href') or False %} {% set fra_ref = tg.xpath('./re/@fra_ref')|count > 0 %} {%- if contains_grammar_link -%} {%- if annotations|count > 0 and not fra_ref -%} ({{ annotations[0].text }}) {% endif -%} {% else %} {% if annotations|count > 0 and not fra_ref %} ({{ annotations[0].text }}) {% endif -%} {% 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 pos = t.attrib.get('pos', '') %} {%- if pos == 'Pron' and t.attrib.get('type') %} {% set pos_type = t.attrib.get('type')|tagfilter(_from, _to) %} {% set pos_text = pos|tagfilter(_from, _to) + " " + pos_type %} {% else %} {% set pos_text = pos|tagfilter(_from, _to) %} {%- endif %} {% set pos_text = pos_text|trim %} {% set link_target = '' %} {% set fra_ref = tg.xpath('./re/@fra_ref') %} {% set explanation = t.attrib.get('type', False) %} {% set explanation_exists = explanation and True %} {% 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 %} {% set grammar_link = t.attrib.get('href', false) %} {# NB: link to grammar should go in somewhere around here. Probably want to do this with a → similar to the munnje -> mun stuff #} {% if explanation_exists and explanation == 'expl' %} {% if pos_text|length > 0 %}({{ pos_text }}) {% endif %} {{ text -}} {%- else %} {% if reference %} {% if pos_text|length > 0 %}({{ pos_text }}) {% endif %}{{ text -}} → {% elif grammar_link %} {% trans %}Bruk: {% endtrans %}{{ text -}} {%- else %} {# NB: swap from and to for these links since these are definitions. #} {% if pos_text|length > 0 %}({{ pos_text }}) {% endif %}{{ 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 : #}