diff options
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 [] |
