Skip to content

Commit

Permalink
Fix template saving (h/t @tritium21)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jun 17, 2016
1 parent c8c4dc4 commit 06b18f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions nikola/plugins/template/jinja.py
Expand Up @@ -29,6 +29,7 @@

from __future__ import unicode_literals
import os
import io
import json
from collections import deque
try:
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion nikola/plugins/template/mako.py
Expand Up @@ -27,6 +27,7 @@
"""Mako template handler."""

from __future__ import unicode_literals, print_function, absolute_import
import io
import os
import shutil
import sys
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 06b18f6

Please sign in to comment.