Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install brodul.recipe.template

How to install brodul.recipe.template

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install brodul.recipe.template
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.2
1.2.1Never BuiltWhy not?
1.2 Available View build log
Windows (64-bit)
1.2
1.2.1Never BuiltWhy not?
1.2 Available View build log
Mac OS X (10.5+)
1.2
1.2.1Never BuiltWhy not?
1.2 Available View build log
Linux (32-bit)
1.2
1.2.1Never BuiltWhy not?
1.2 Available View build log
Linux (64-bit)
1.2.1 Available View build log
1.2 Available View build log
 
License
BSD
Lastest release
version 1.2.1 on Jan 9th, 2014

brodul.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: http://pypi.python.org/pypi/brodul.recipe.template/

https://secure.travis-ci.org/brodul/amplecode.recipe.template.png

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 = brodul.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 = brodul.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 }}

Note

{{ parts.bar.dashed-value }} won't work, but you can access it as a dict key.

Dashed value in the same part

If there is a dashed-value in brodul.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 = brodul.recipe.template
input = foo.txt.jinja2
output = foo.txt
jinja2_filters = filter.bar

Changelog

See the CHANGELOG file

License

See the LICENSE file

Todo

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

Subscribe to package updates

Last updated Jan 9th, 2014

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.