Commits

Ralph Bean committed 3bb3686

Pass filename to mako templates for easier debugging.

Comments (0)

Files changed (3)

tw2/core/middleware.py

         template engine.
         (default: {
             'mako':['mak', 'mako'],
-            'genshi':['html'],
-            'jinja':['html', 'jinja'],
-            'kajiki':['html', 'kajiki'],
+            'genshi':['genshi', 'html'],
+            'jinja':['jinja', 'html'],
+            'kajiki':['kajiki', 'html'],
         })
 
     `script_name`
     strict_engine_selection = True
     rendering_extension_lookup = {
         'mako': ['mak', 'mako'],
-        'genshi': ['html'],
-        'jinja': ['jinja', 'html'],
-        'kajiki': ['kajiki', 'html'],
+        'genshi': ['genshi', 'html'],
+        'jinja':['jinja', 'html'],
+        'kajiki':['kajiki', 'html'],
     }
     script_name = ''
 

tw2/core/templating.py

 
 
 @memoize
-def get_render_callable(engine_name, displays_on, src):
+def get_render_callable(engine_name, displays_on, src, filename=None):
     """ Returns a function that takes a template source and kwargs. """
 
     # See the discussion here re: `displays_on` -- http://bit.ly/JRqbRw
 
     if engine_name == 'mako':
         import mako.template
-        tmpl = mako.template.Template(src)
+        tmpl = mako.template.Template(text=src, filename=filename)
         return lambda kwargs: literal(tmpl.render(**kwargs))
     elif engine_name in ('genshi', 'genshi_abs'):
         import genshi.template
     Makes use of *all* other functions in this module.
     """
 
-    engine_name = get_engine_name(template_name, mw)
+    # Determine the engine name
+    if not inline:
+        engine_name = get_engine_name(template_name, mw)
+    else:
+        engine_name = inline
+
+    # Load the template source
     source = get_source(engine_name, template_name, inline)
-    callback = get_render_callable(engine_name, displays_on, source)
+    # Establish the render function
+    callback = get_render_callable(
+        engine_name, displays_on, source, template_name)
+    # Do it
     return callback(kwargs)

tw2/core/widgets.py

                 if hasattr(self, p):
                     kwargs[p] = getattr(self, p)
 
-        # Determine the engine name
-        if self.inline_engine_name:
-            engine_name = self.inline_engine_name
-        else:
-            engine_name = templating.get_engine_name(self.template)
-
-        # Load the template source
-        template_source = templating.get_source(
-            engine_name, self.template, self.inline_engine_name)
-
-        # Establish the render function
-        render = templating.get_render_callable(
-            engine_name, displays_on, template_source)
-
-        # Do it
-        return render(kwargs)
+        return templating.render(
+            self.template,
+            displays_on,
+            kwargs,
+            self.inline_engine_name,
+            mw,
+        )
 
     def _get_default_displays_on(self, mw):
         if not self.parent: