Skip to content
Permalink
Browse files
Fix template saving (h/t @tritium21)
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jun 17, 2016
1 parent c8c4dc4 commit 06b18f6cd8a5adb06a90e60f04e07f92f620a18a
Showing with 6 additions and 4 deletions.
  1. +4 −3 nikola/plugins/template/jinja.py
  2. +2 −1 nikola/plugins/template/mako.py
@@ -29,6 +29,7 @@

from __future__ import unicode_literals
import os
import io
import json
from collections import deque
try:
@@ -91,11 +92,11 @@ def render_template(self, template_name, output_name, context):
if jinja2 is None:
req_missing(['jinja2'], 'use this theme')
template = self.lookup.get_template(template_name)
output = template.render(**context)
data = template.render(**context)
if output_name is not None:
makedirs(os.path.dirname(output_name))
with open(output_name, 'w+') as output:
output.write(output.encode('utf8'))
with io.open(output_name, 'w', encoding='utf-8') as output:
output.write(data)
return output

def render_template_to_string(self, template, context):
@@ -27,6 +27,7 @@
"""Mako template handler."""

from __future__ import unicode_literals, print_function, absolute_import
import io
import os
import shutil
import sys
@@ -108,7 +109,7 @@ def render_template(self, template_name, output_name, context):
data = template.render_unicode(**context)
if output_name is not None:
makedirs(os.path.dirname(output_name))
with open(output_name, 'w+') as output:
with io.open(output_name, 'w', encoding='utf-8') as output:
output.write(data)
return data

0 comments on commit 06b18f6

Please sign in to comment.