Buildout recipe for making files out of Jinja2 templates
Project description
=========================
sact.recipe.jinjatemplate
=========================
sact.recipe.jinjatemplate is a Buildout recipe for generating files
using Jinja2 templates. It's a friendly fork of
amplecode.recipe.template (no more maintained).
Buildout Options
================
* template-file (required): One or more Jinja2 template file paths.
* target-file (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.
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
===============
The `split` filter was removed in the 1.2. It is still possible for a
recipe option to contain one or more values, separated by whitespace::
#!/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 = sact.recipe.jinjatemplate
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 = sact.recipe.jinjatemplate
base-dir = myapp
template-file =
foo.txt.jinja2
bar.sh.jinja2
target-file =
foo.txt
bar.sh
target-executable =
false
true
project_name = Another Example
author = Me
Templating Shell Scripts
========================
If you use this recipe to template shell scripts, it is STRONGLY
recommanded to use the filter 'shell_quote' to avoid bad surprises::
#!/bin/sh
rm -rf -- {{ path|shell_quote }}
Version 1.3 (2015-07-07)
------------------------
* Added Jinja function to generate a random string
Version 1.2.1 (2015-01-27)
--------------------------
* Fix packaging information
Version 1.2 (2015-01-23)
------------------------
* Updates tests
* Add the 'type' builtin in the Environment globals
* Update the documentation
Version 1.1 (2015-01-21)
------------------------
* Update bootstrap.py.
* Add a 'shell_quote' Jinja filter.
* Cleanup code.
* Python3 compliance (seems to work fine with 3.4).
* Add some python builtins like (any, all, bool, zip, sorted, len, int, min, max) available in templates.
* Add more tests.
Version 1.0 (2013-11-27)
------------------------
* Initial version
sact.recipe.jinjatemplate
=========================
sact.recipe.jinjatemplate is a Buildout recipe for generating files
using Jinja2 templates. It's a friendly fork of
amplecode.recipe.template (no more maintained).
Buildout Options
================
* template-file (required): One or more Jinja2 template file paths.
* target-file (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.
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
===============
The `split` filter was removed in the 1.2. It is still possible for a
recipe option to contain one or more values, separated by whitespace::
#!/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 = sact.recipe.jinjatemplate
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 = sact.recipe.jinjatemplate
base-dir = myapp
template-file =
foo.txt.jinja2
bar.sh.jinja2
target-file =
foo.txt
bar.sh
target-executable =
false
true
project_name = Another Example
author = Me
Templating Shell Scripts
========================
If you use this recipe to template shell scripts, it is STRONGLY
recommanded to use the filter 'shell_quote' to avoid bad surprises::
#!/bin/sh
rm -rf -- {{ path|shell_quote }}
Version 1.3 (2015-07-07)
------------------------
* Added Jinja function to generate a random string
Version 1.2.1 (2015-01-27)
--------------------------
* Fix packaging information
Version 1.2 (2015-01-23)
------------------------
* Updates tests
* Add the 'type' builtin in the Environment globals
* Update the documentation
Version 1.1 (2015-01-21)
------------------------
* Update bootstrap.py.
* Add a 'shell_quote' Jinja filter.
* Cleanup code.
* Python3 compliance (seems to work fine with 3.4).
* Add some python builtins like (any, all, bool, zip, sorted, len, int, min, max) available in templates.
* Add more tests.
Version 1.0 (2013-11-27)
------------------------
* Initial version
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file sact.recipe.jinjatemplate-1.3.0.tar.gz
.
File metadata
- Download URL: sact.recipe.jinjatemplate-1.3.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8688719e63df7c6c8e88d843eed9cddbc2a5869165f5037cdd829346beb9b3a |
|
MD5 | 065e07e8f91a82b26d77e612c261ce44 |
|
BLAKE2b-256 | 99a0ed8a3c5dbec178c93b99e802b593b9ef64e0273b84c50236a7acf0647463 |