Directory/filesystem-level templating using Jinja2
Project description
Mondir
Jinja2 templates for whole directories / multiple files.
Installation
pip3 install mondir
Usage
Files in the input template directory can use both normal Jinja syntax and syntax extensions introduced by Mondir. File and directory names can contain Jinja syntax, too.
For instance, to output a file for each entry in a list of names, you could
place a file named greeting-for-{{ name }}.txt
in a directory and fill it
with:
{% thisfile for name in names -%}
Hello {{ name }}!
Templating this out is as simple as this:
from mondir import DirTemplate
template = DirTemplate("template_input_dir")
template.render("output_dir", names=["John", "Jane", "Alice", "Bob"])
A full tutorial is available in the docs.
Similar projects
- dirtempl: Same idea as this one, but doesn't support Jinja2 template syntax.
- dirtemplate: Also the same idea and also uses Jinja2. But I only found out about it after I wrote mine and now the sunk cost fallacy compels me to stick with it no matter what.
Name explanation
Given that the obvious names from the "Similar projects" section were taken and my working title (fisyte, for filesystem templates) sounded dumb, I stole how Jinja got its name, i.e. by using a word that means temple (because that sounds a bit like template) in another language. The first translation of temple on Wiktionary that also contains the fragment dir (for directory) is the Bengali word mondir. So that's it.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.