Skip to content

Commit

Permalink
- osc.cli.render: added "render_only" method to class Renderer
Browse files Browse the repository at this point in the history
It simply returns the rendered template (no data is printed to
the user).
  • Loading branch information
marcus-h committed Dec 29, 2012
1 parent 4a63d8e commit 0391d71
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions osc/cli/render.py
Expand Up @@ -60,19 +60,29 @@ def _custom_template_names(self, template):
ret.append(splitted[0] + '/' + name)
return ret

def _render(self, template, out, *args, **kwargs):
def render_only(self, template, *args, **kwargs):
"""Renders template template.
out is a file or file-like object to which the rendered
template should be written to.
The rendered template is returned (no data will be written
or printed).
*args and **kwargs are passed to jinja2 Template's render
method.
"""
names = self._custom_template_names(template)
names.append(template)
tmpl = self._env.select_template(names)
text = tmpl.render(*args, **kwargs)
return tmpl.render(*args, **kwargs)

def _render(self, template, out, *args, **kwargs):
"""Renders template template.
out is a file or file-like object to which the rendered
template should be written to.
*args and **kwargs are passed to the render_only method.
"""
text = self.render_only(template, *args, **kwargs)
try:
out.write(text)
except UnicodeEncodeError:
Expand Down

0 comments on commit 0391d71

Please sign in to comment.