Skip to content

Commit

Permalink
baby steps
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed May 24, 2015
1 parent 4d3a779 commit 14f00ef
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions v7/jade/jade.py
Expand Up @@ -32,9 +32,9 @@
try:
import jinja2
from jinja2 import meta
import pyjade
except ImportError:
jinja2 = None # NOQA
import pyjade
pyjade = None # NOQA

from nikola.plugin_categories import TemplateSystem
from nikola.utils import makedirs, req_missing
Expand All @@ -49,17 +49,17 @@ class JinjaTemplates(TemplateSystem):

def __init__(self):
""" initialize Jinja2 wrapper with extended set of filters"""
if jinja2 is None:
return
if pyjade is None:
req_missing(['pyjade'], 'build this site (compile Jade)')
self.lookup = jinja2.Environment(extensions=['pyjade.ext.jinja.PyJadeExtension'])
self.lookup.filters['tojson'] = json.dumps
self.lookup.filters['istuple'] = lambda x: isinstance(x, tuple)
self.lookup.globals['enumerate'] = enumerate

def set_directories(self, directories, cache_folder):
"""Create a template lookup."""
if jinja2 is None:
req_missing(['jinja2'], 'use this theme')
if pyjade is None:
req_missing(['pyjade'], 'use this theme')
self.lookup.loader = jinja2.FileSystemLoader(directories,
encoding='utf-8')

Expand All @@ -70,8 +70,8 @@ def set_site(self, site):

def render_template(self, template_name, output_name, context):
"""Render the template into output_name using context."""
if jinja2 is None:
req_missing(['jinja2'], 'use this theme')
if pyjade is None:
req_missing(['pyjade'], 'use this theme')
if not template_name.endswith('.jade'):
template_name = os.path.splitext(template_name)[0]+'.jade'
template = self.lookup.get_template(template_name)
Expand Down

0 comments on commit 14f00ef

Please sign in to comment.