diff options
| author | 2012-12-12 20:15:48 -0300 | |
|---|---|---|
| committer | 2012-12-12 20:15:48 -0300 | |
| commit | 0f2c04e70a0ffdd0892d6970cafbcd952d221db5 (patch) | |
| tree | d36f7747c4b9cb5c5e00cae5b137d22214b1c7be /nikola/plugins/template_jinja.py | |
| parent | ca1f5a392261a7c6b82b5ac1015427605909d8c9 (diff) | |
Imported Upstream version 5upstream/5
Diffstat (limited to 'nikola/plugins/template_jinja.py')
| -rw-r--r-- | nikola/plugins/template_jinja.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/nikola/plugins/template_jinja.py b/nikola/plugins/template_jinja.py new file mode 100644 index 0000000..0893cf7 --- /dev/null +++ b/nikola/plugins/template_jinja.py @@ -0,0 +1,38 @@ +"""Jinja template handlers""" + +import os +import jinja2 + +from nikola.plugin_categories import TemplateSystem + + +class JinjaTemplates(TemplateSystem): + """Wrapper for Jinja2 templates.""" + + name = "jinja" + lookup = None + + def set_directories(self, directories): + """Createa template lookup.""" + self.lookup = jinja2.Environment(loader=jinja2.FileSystemLoader( + directories, + encoding='utf-8', + )) + + def render_template(self, template_name, output_name, context): + """Render the template into output_name using context.""" + + template = self.lookup.get_template(template_name) + output = template.render(**context) + if output_name is not None: + try: + os.makedirs(os.path.dirname(output_name)) + except: + pass + with open(output_name, 'w+') as output: + output.write(output.encode('utf8')) + return output + + def template_deps(self, template_name): + # FIXME: unimplemented + return [] |
