Permalink
Browse files

Pass filename to mako templates for easier debugging.

  • Loading branch information...
ralphbean committed Apr 30, 2012
1 parent 55f1fbe commit 5e63adcbed071464ef0b10096a3338600561886b
Showing with 26 additions and 26 deletions.
  1. +6 −6 tw2/core/middleware.py
  2. +13 −4 tw2/core/templating.py
  3. +7 −16 tw2/core/widgets.py
@@ -85,9 +85,9 @@ class Config(object):
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`
@@ -115,9 +115,9 @@ class Config(object):
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 = ''
@@ -94,14 +94,14 @@ def get_source(engine_name, template, inline=False):
@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
@@ -125,7 +125,16 @@ def render(template_name, displays_on, kwargs, inline=False, mw=None):
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)
@@ -426,22 +426,13 @@ def generate_output(self, displays_on):
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:

0 comments on commit 5e63adc

Please sign in to comment.