Quick example of generating documents by rendering data from a YAML file through a Jinja2 template. The target output is Latex vhistory data (revs.tex
) which will be included in main document (main.tex
). The output is generated by a Python script (create_revs_tex.py
) from YAML data (revs.yaml
).
import yaml
from jinja2 import Template
# For this example, assume that stdout will be redirected to `revs.tex`.
# In the template, the `{#--#}` entries are used to eat unwanted whitespace.
print Template(r"""
{#--#}
\begin{versionhistory}
{%- for r in revs %}
\vhEntry {#- -#}
{ {{- r.number -}} } {#--#}
{ {{- r.date -}} } {#--#}
{ {{- r.author -}} } {#--#}
{ {{- r.comments -}} }
{%- endfor %}
\end{versionhistory}
""").render(revs=yaml.load(open("revs.yaml")))