diff piecrust/templating/jinjaengine.py @ 855:448710d84121

refactor: Get the taxonomy support back to a functional state. There's now a taxonomy content source that wraps another normal content source like a blog posts' source. It works in tandem with a taxonomy content pipeline that will do the heavy lifting of figuring out what kind of terms exist and need to be baked.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 06 Jun 2017 00:26:21 -0700
parents 4850f8c21b6e
children 5c5b85d4f17d
line wrap: on
line diff
--- a/piecrust/templating/jinjaengine.py	Sun Jun 04 23:34:28 2017 -0700
+++ b/piecrust/templating/jinjaengine.py	Tue Jun 06 00:26:21 2017 -0700
@@ -84,21 +84,30 @@
         raise err from tse
 
     def _ensureLoaded(self):
-        if self.env:
+        if self.env is not None:
             return
 
+        stats = self.app.env.stats
+        stats.registerTimer('JinjaTemplateEngineEnvironmentSetup',
+                            raise_if_registered=False)
+        with stats.timerScope('JinjaTemplateEngineEnvironmentSetup'):
+            self._load()
+
+    def _load(self):
+        get_config = self.app.config.get
+
         # Get the list of extensions to load.
-        ext_names = self.app.config.get('jinja/extensions', [])
+        ext_names = get_config('jinja/extensions', [])
         if not isinstance(ext_names, list):
             ext_names = [ext_names]
 
         # Turn on autoescape by default.
-        autoescape = self.app.config.get('twig/auto_escape')
+        autoescape = get_config('twig/auto_escape')
         if autoescape is not None:
             logger.warning("The `twig/auto_escape` setting is now called "
                            "`jinja/auto_escape`.")
         else:
-            autoescape = self.app.config.get('jinja/auto_escape', True)
+            autoescape = get_config('jinja/auto_escape', True)
         if autoescape:
             ext_names.append('autoescape')