Commit 7fa2695a authored by Julien Muchembled's avatar Julien Muchembled

jinja2: rendered -> output, template -> url/inline

parent 70da5e82
......@@ -5,15 +5,17 @@
Similar to the default recipe but the template syntax is Jinja2 instead of
buildout. Other significant differences are:
- For historical reasons, the generated file is specified with ``rendered``
instead of ``output``.
- For historical reasons, the template is specified with ``template`` only
and an inline template is prefixed with ``inline:`` + an optional newline.
- Rendering, and download if requested, is done during the install phase.
- Dependencies are explicit (see ``context`` option) instead of deduced from
the template.
- Some extra features (options detailed below).
For backward compatibility, the following old options are still supported:
- The generated file can be specified with ``rendered`` instead of ``output``.
- The template can be specified with ``template`` instead of ``url``/``inline``.
An inline template is prefixed with ``inline:`` + an optional newline.
Example demonstrating some types::
>>> write('buildout.cfg',
......
......@@ -71,24 +71,31 @@ class Recipe(object):
self.mode = int(mode, 8) if mode else None
self._init(name, options)
def _init(self, name, options):
self.output = options['output']
rendered = options.get('inline')
def _template(self, options):
inline = options.get('inline')
try:
url = options['url']
except KeyError:
if rendered is None:
if inline is None:
raise
if self.md5sum:
raise UserError("options 'inline' & 'md5sum' conflict")
self.md5sum = True # tell update() to do nothing
self.rendered = rendered
return True, inline
else:
if rendered:
if inline:
raise UserError("options 'inline' & 'url' conflict")
return False, url
def _init(self, name, options):
self.output = options['output']
inline, template = self._template(options)
if inline:
self.rendered = template
else:
options_sub = options._sub
self.rendered = '$'.join(options_sub(s, None)
for s in self._read(url).split('$$'))
for s in self._read(template).split('$$'))
def _read(self, url, *args):
path, is_temp = zc.buildout.download.Download(
......
......@@ -165,8 +165,17 @@ class Recipe(Recipe):
delimiter=import_delimiter)
else:
loader = None
self.output = options['rendered']
self.template = options['template']
try:
self.output = options['output']
except KeyError: # BBB
self.output = options['rendered']
template = options['template']
if template.startswith('inline:'):
self.template = True, template[7:].lstrip('\r\n')
else:
self.template = False, template
else:
self.template = self._template(options)
extension_list = [x for x in (y.strip()
for y in options.get('extensions', '').split()) if x]
self.context = context = DEFAULT_CONTEXT.copy()
......@@ -187,11 +196,10 @@ class Recipe(Recipe):
loader=loader)
def _render(self):
template = self.template
env = self.env
if template.startswith('inline:'):
source = template[7:].lstrip('\r\n')
compiled_source = env.compile(source, filename='<inline>')
inline, template = self.template
if inline:
compiled_source = env.compile(template, filename='<inline>')
else:
try:
compiled_source = compiled_source_cache[template]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment