Buildout recipe for making files out of Jinja2 templates
Project description
gobre.recipe.template is a fork of amplecode.recipe.template, a Buildout recipe for generating files using Jinja2 templates. The recipe configures a Jinja2 environment, by default relative to the Buildout directory, allowing templates to extend and include other templates relative to the environment.
Downloads are available from pypi: https://pypi.org/project/gobre.recipe.template/
Buildout Options
template-file or input (required): One or more Jinja2 template file paths.
target-file or output (required): One of more target file paths. The number of files must match the number of template files.
base-dir: Base directory of the Jinja2 environment. Template file paths are relative to this directory. Default is the Buildout directory.
target-executable: One or more boolean flags (yes|no|true|false|1|0) indicating the executability of the target files. If only one flag is given it is applied to all target files.
eggs: Reserved for a list of eggs, conveniently converted into a pkg_resources.WorkingSet when specified
jinja2_filters: custom filter functions separated by white-space
Additional options are simply forwarded to the templates, and options from all the other parts are made available through parts.<part-name>.<option-name> and parts[<part-name>][<option-name>].
Lists of Values
It is possible for a recipe option to contain one or more values, separated by whitespace. A split filter is available for when you want to iterate over the whitespace separated values in your Jinja2 template:
#!/bin/sh
{% for cmd in cmds|split %}
echo "{{ cmd }}"
{% endfor %}
Minimal Example
foo.txt is created from foo.txt.jinja2 without any extra options:
[buildout] parts = foo [foo] recipe = gobre.recipe.template template-file = foo.txt.jinja2 target-file = foo.txt
Larger Example
foo.txt is created from myapp/foo.txt.jinja2, bar.sh is created from myapp/bar.sh.jinja2, the second will be executable, and both templates can utilize the additional options specified:
[buildout]
parts = foo
[foo]
recipe = gobre.recipe.template
base-dir = myapp
template-file =
foo.txt.jinja2
bar.sh.jinja2
input =
foo.txt
bar.sh
output =
false
true
project_name = Another Example
author = Me
[bar]
dashed-value = borg
value = cash
foo.txt.jinja2:
{{ parts.bar['dashed-value'] }}
{{ parts.bar.value }}
{{ author }}
Dashed value in the same part
If there is a dashed-value in gobre.recipe.template part and you would like to reference it, use:
{{context['dashed-value']}}
Custom filters
The filter function is located in the same directory as the buildout.cfg in a filter.py file. If you want to use more filters separate them with a white space.
[buildout] parts = foo [foo] recipe = gobre.recipe.template input = foo.txt.jinja2 output = foo.txt jinja2_filters = filter.bar
Changelog
See the CHANGELOG file
License
See the LICENSE file
Why this fork
there should be an input and output option in buildout (since the ‘-’ in ‘target-file’ char is parsed by jinja2)
custom filters support
templates should not have the ability to change state of buildout
Gather the changes of the other forks (buildout 2 support and Python 3 support + fixes into a new package).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gobre.recipe.template-2.0.tar.gz.
File metadata
- Download URL: gobre.recipe.template-2.0.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7578c5d7eb071a0d0659de117853156fd54a92a445cdbe9263e4b0595961a754
|
|
| MD5 |
a7cb5fa7eb07052a7187078d48a5b700
|
|
| BLAKE2b-256 |
90ec26bdb47dff13187c985fcf01955038d15a57b00a33a4dc081df148f88dac
|
File details
Details for the file gobre.recipe.template-2.0-py3-none-any.whl.
File metadata
- Download URL: gobre.recipe.template-2.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
306da769cc222764df614dd4a21ed6d661fe941fc550cdaedb702d3221d9fc84
|
|
| MD5 |
04484931509807f8aa0686c0a436c38d
|
|
| BLAKE2b-256 |
ccfc96016fcd3b1126bce541668d3401dc34139925e6fd009cd6c585a12582ee
|