diff piecrust/templating/jinja/environment.py @ 907:3e69f18912f5

jinja: Remove Twig compatibility, add timer, improve code. - Add a timer for keeping track of extensions' performance. - Use the `select_template` function from Jinja to cut down on a few lines of code.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 23 Jul 2017 08:30:47 -0700
parents 41b0c94f9833
children
line wrap: on
line diff
--- a/piecrust/templating/jinja/environment.py	Sun Jul 23 08:27:18 2017 -0700
+++ b/piecrust/templating/jinja/environment.py	Sun Jul 23 08:30:47 2017 -0700
@@ -20,12 +20,14 @@
 
         # Before we create the base Environement, let's figure out the options
         # we want to pass to it.
-        twig_compatibility_mode = app.config.get('jinja/twig_compatibility')
-
+        #
         # Disable auto-reload when we're baking.
         if app.config.get('baker/is_baking'):
             kwargs.setdefault('auto_reload', False)
 
+        # Don't unload templates from the cache.
+        kwargs.setdefault('cache_size', -1)
+
         # Let the user override most Jinja options via the site config.
         for name in ['block_start_string', 'block_end_string',
                      'variable_start_string', 'variable_end_string',
@@ -47,10 +49,6 @@
             from jinja2 import StrictUndefined
             kwargs.setdefault('undefined', StrictUndefined)
 
-        # Twig trims blocks.
-        if twig_compatibility_mode is True:
-            kwargs['trim_blocks'] = True
-
         # All good! Create the Environment.
         super(PieCrustEnvironment, self).__init__(*args, **kwargs)
 
@@ -78,10 +76,7 @@
             'emaildate': get_email_date,
             'date': get_date})
 
-        # Backwards compatibility with Twig.
-        if twig_compatibility_mode is True:
-            self.filters['raw'] = self.filters['safe']
-            self.globals['pcfail'] = raise_exception
+        self.filters['raw'] = self.filters['safe']
 
     def _paginate(self, value, items_per_page=5):
         ctx = self.app.env.render_ctx_stack.current_ctx