comparison piecrust/templating/jinjaengine.py @ 59:e3e3de44377c

Better handling of Jinja configuration.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 26 Aug 2014 23:20:19 -0700
parents 002fa58f54dc
children 071cc99b1779
comparison
equal deleted inserted replaced
58:95590732e4c9 59:e3e3de44377c
52 pass 52 pass
53 if tpl is None: 53 if tpl is None:
54 raise TemplateNotFoundError() 54 raise TemplateNotFoundError()
55 return tpl.render(data) 55 return tpl.render(data)
56 56
57
58 def _ensureLoaded(self): 57 def _ensureLoaded(self):
59 if self.env: 58 if self.env:
60 return 59 return
60
61 autoescape = self.app.config.get('jinja/auto_escape')
62 if autoescape is None:
63 autoescape = self.app.config.get('twig/auto_escape')
64 if autoescape is None:
65 autoescape = True
66
67 logger.debug("Creating Jinja environment with folders: %s" %
68 self.app.templates_dirs)
61 loader = FileSystemLoader(self.app.templates_dirs) 69 loader = FileSystemLoader(self.app.templates_dirs)
70 extensions = [
71 PieCrustHighlightExtension,
72 PieCrustCacheExtension]
73 if autoescape:
74 extensions.append('jinja2.ext.autoescape')
62 self.env = PieCrustEnvironment( 75 self.env = PieCrustEnvironment(
63 self.app, 76 self.app,
64 loader=loader, 77 loader=loader,
65 extensions=['jinja2.ext.autoescape', 78 extensions=extensions)
66 PieCrustHighlightExtension,
67 PieCrustCacheExtension])
68 79
69 80
70 class PieCrustEnvironment(Environment): 81 class PieCrustEnvironment(Environment):
71 def __init__(self, app, *args, **kwargs): 82 def __init__(self, app, *args, **kwargs):
72 super(PieCrustEnvironment, self).__init__(*args, **kwargs) 83 super(PieCrustEnvironment, self).__init__(*args, **kwargs)