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.
- yamldirs creates whole directories from
YAML specs. While working on Mondir, I considered having a similar file
format as an intermediate step between the templates and the final output
(which would have made a couple of things easier to implement and would have
had the benefit of making the output of Jinja's regular
render()meaningful), but dropped the idea over performance concerns.
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.
Changelog
0.2.0
DirTemplate.render()now raises newly introduced exceptionsTemplateLoadingError,TemplateRenderingError, andTemplateOutputErrorinstead of merely passing along exceptions from Jinja/Python'sos, allowing users to see which files/params were responsible.
Metadata
Release files for mondir 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mondir-0.2.0.tar.gz | 12.8 kB | Without provenance | Details for mondir-0.2.0.tar.gz |
Release files / mondir-0.2.0.tar.gz
| Download URL | mondir-0.2.0.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
87835fb8406d4b515eb39e5d9cdf6b1ae4fdfbfdfa1c779c994b80a69a611b61
|
|
BLAKE2b-256 checksum How to use checksums |
26225d19d343b87aa0a4656c67aea7bf057b33099e7bc5a53efd5b1c936ce0a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.0rc3
|
Security for mondir 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.