File: macros.jinja2

package info (click to toggle)
python-stetl 1.0.9%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 89,428 kB
  • ctags: 720
  • sloc: python: 3,527; xml: 699; sql: 428; makefile: 153; sh: 45
file content (44 lines) | stat: -rw-r--r-- 1,315 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

{# Macro that renders a bounding box element from feature list #}
{% macro render_bounded_by(features) -%}

    {# first assemble all latitudes and longitudes #}
    {% set longitudes = [] %}
    {% set latitudes = [] %}

    {% for feature in features %}
        {% do longitudes.append(feature.lon) %}
        {% do latitudes.append(feature.lat) %}
    {% endfor %}

    <!-- Rendered by macro render_bounded_by() -->
    {# use the maximum and minimum Jinja2 Filters to get max/min from lists #}
    <gml:boundedBy>
        <gml:Box>
            <gml:coord>
                <gml:X>{{ longitudes|minimum }}</gml:X>
                <gml:Y>{{ latitudes|minimum }}</gml:Y>
            </gml:coord>
            <gml:coord>
                <gml:X>{{ longitudes|maximum }}</gml:X>
                <gml:Y>{{ latitudes|maximum }}</gml:Y>
            </gml:coord>
        </gml:Box>
    </gml:boundedBy>
{%- endmacro %}

{# Macro that renders a name element #}
{% macro render_name(name) -%}
    <!-- Rendered by macro render_name() -->
    <gml:name>
       {{ name }}
    </gml:name>
{%- endmacro %}

{# Macro that renders any element with tag and content :-) #}
{% macro render_element(tag, content) -%}
    <!-- Rendered by macro render_element() -->
    <{{tag}}>
       {{ content }}
    </{{tag}}>
{%- endmacro %}