Debian Codegraph @

examples/basics/10_jinja2_templating/readme.txt

raw
1 This example, or better a series of examples, shows an unconventional but exciting new
2 way for transforming source data into complex/rich XML/GML. Possibly "transforming"
3 is not the proper term but "substitution".
4
5 Enter the Jinja...Within many web-frameworks, the use of "templating" is common.
6 think of JSP (Java), ASP (.NET), PHP even in JavaScript (e.g. Mustache).
7 Within Python there are a zillion templating languages to choose from. From plain
8 built-in $string substitution up to fullfledged programming. Django Templating, Gensha, Mako.
9 See https://wiki.python.org/moin/Templating
10
11 Within Stetl we choose to support two languages for now, both derived from a single
12 TemplatingFilter class: String templating (see example 9) and Jinja2 templating.
13
14 This example shows several Jinja2 templating examples from basic to very advanced.
15 All are bundled within the single etl.cfg file as Stetl allows multiple ETL chains
16 defined in a single config file.
17
18 For all examples, the dirs are as follows:
19
20 - input/: all input files
21 - output/: all generated output files
22 - templates/: the Jinja2 templates and macros
23
24 EXAMPLE 1 - simple Jinja2 templating: JSON to XML
25 input/cities.json is converted to output/cities.xml using the template templates/cities-json2xml.jinja2
26
27 EXAMPLE 2 - more advanced Jinja2 templating : JSON to GML (
28 input/cities.json is converted to output/cities.gml (GML FeatureCollection) using the
29 template templates/cities-json2gml.jinja2
30 Shows the use of Jinja2 Globals (input/globals.json), global/static values that are
31 always available in the template and the use of Jinja2 Macros (template/macros.jinja2) for recurring
32 tasks.
33
34 EXAMPLE 3 - advanced Jinja2 templating - GeoJSON to GML - and reading from URL
35 input/cities-gjson.json is converted to output/cities-gjson.gml (GML FeatureCollection) using the
36 template templates/cities-gjson2gml.jinja2. Shows the use of advanced Jinja2 Filters within Stetl that
37 can transform GeoJSON Geometries to GML Geometries. Also shows that input and/or globals can be fetched from
38 a remote URL.
39
40 EXAMPLE 4 - data harmonization for INSPIRE: transform local Dutch address data to INSPIRE Annex I Addresses (AD)
41 input/addresses.csv is converted to output/inspire-addresses.gml (GML Spatial dataset) using the
42 template templates/addresses2inspire-ad.jinja2. Shows that data transformation for INSPIRE doesn't need to be
43 hard. Usually the source data is in tabular form, here a CSV file. The required data format
44 for INSPIRE is often "bloated" with boilerplate encodings. Here templating makes lots of sense.
45
46
47
48