diff options
| author | 2012-12-12 19:58:42 -0300 | |
|---|---|---|
| committer | 2012-12-12 19:58:42 -0300 | |
| commit | ca1f5a392261a7c6b82b5ac1015427605909d8c9 (patch) | |
| tree | f91146c9340c6c78e84aaf6b92053386397e2069 /nikola/jinja_templates.py | |
Imported Upstream version 4.0.3upstream/4.0.3
Diffstat (limited to 'nikola/jinja_templates.py')
| -rw-r--r-- | nikola/jinja_templates.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/nikola/jinja_templates.py b/nikola/jinja_templates.py new file mode 100644 index 0000000..f55465f --- /dev/null +++ b/nikola/jinja_templates.py @@ -0,0 +1,37 @@ +######################################## +# Jinja template handlers +######################################## + +import os + +import jinja2 + +lookup = None +cache = {} + + +def get_template_lookup(directories): + return jinja2.Environment(loader=jinja2.FileSystemLoader( + directories, + encoding='utf-8', + )) + + +def render_template(template_name, output_name, context, global_context): + template = lookup.get_template(template_name) + local_context = {} + local_context.update(global_context) + local_context.update(context) + output = template.render(**local_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(template_name): + return [] |
