aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mako
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-12-14 01:11:48 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-12-14 01:11:48 +0000
commit03011540d4e6dfb2133849ec0d8faff8d27ebec1 (patch)
tree2555521775137e8f5d4e48bdd2c3f724bff14597 /lib/mako
parent6cdace7ca2ab7d9b3782fa425cb939dc3c5497ca (diff)
downloadexternal_python_mako-03011540d4e6dfb2133849ec0d8faff8d27ebec1.tar.gz
external_python_mako-03011540d4e6dfb2133849ec0d8faff8d27ebec1.tar.bz2
external_python_mako-03011540d4e6dfb2133849ec0d8faff8d27ebec1.zip
some tweaking around with the render method, template lookups, getting direct def calls to work
Diffstat (limited to 'lib/mako')
-rw-r--r--lib/mako/codegen.py8
-rw-r--r--lib/mako/runtime.py27
-rw-r--r--lib/mako/template.py2
3 files changed, 20 insertions, 17 deletions
diff --git a/lib/mako/codegen.py b/lib/mako/codegen.py
index 81272ea..072ce54 100644
--- a/lib/mako/codegen.py
+++ b/lib/mako/codegen.py
@@ -46,7 +46,7 @@ class _GenerateRenderMethod(object):
pagetag = None
else:
(pagetag, defs) = self.write_toplevel()
- name = "render"
+ name = "render_body"
args = None
buffered = filtered = False
self.compiler.pagetag = pagetag
@@ -172,10 +172,10 @@ class _GenerateRenderMethod(object):
self.printer.writelines(
"def _mako_get_namespace(context, name):",
"try:",
- "return context.namespaces[(render, name)]",
+ "return context.namespaces[(__name__, name)]",
"except KeyError:",
"_mako_generate_namespaces(context)",
- "return context.namespaces[(render, name)]",
+ "return context.namespaces[(__name__, name)]",
None,None
)
self.printer.writeline("def _mako_generate_namespaces(context):")
@@ -202,7 +202,7 @@ class _GenerateRenderMethod(object):
self.printer.writeline("ns = runtime.Namespace(%s, context._clean_inheritance_tokens(), templateuri=%s, callables=%s, calling_uri=_template_uri)" % (repr(node.name), node.parsed_attributes.get('file', 'None'), callable_name))
if eval(node.attributes.get('inheritable', "False")):
self.printer.writeline("context['self'].%s = ns" % (node.name))
- self.printer.writeline("context.namespaces[(render, %s)] = ns" % repr(node.name))
+ self.printer.writeline("context.namespaces[(__name__, %s)] = ns" % repr(node.name))
self.printer.write("\n")
if not len(namespaces):
self.printer.writeline("pass")
diff --git a/lib/mako/runtime.py b/lib/mako/runtime.py
index 4f1792c..42fb036 100644
--- a/lib/mako/runtime.py
+++ b/lib/mako/runtime.py
@@ -85,9 +85,11 @@ class Namespace(object):
self._module = module
if templateuri is not None:
self.template = _lookup_template(context, templateuri, calling_uri)
+ self._templateuri = self.template.module._template_uri
else:
self.template = template
- self._templateuri = templateuri
+ if self.template is not None:
+ self._templateuri = self.template.module._template_uri
self.context = context
self.inherits = inherits
if callables is not None:
@@ -113,6 +115,9 @@ class Namespace(object):
self.context.namespaces[key] = ns
return ns
+ def get_template(self, uri):
+ return _lookup_template(self.context, uri, self._templateuri)
+
def get_cached(self, key, **kwargs):
if self.template:
if self.template.cache_dir:
@@ -155,15 +160,11 @@ class Namespace(object):
except KeyError:
pass
if self.template is not None:
- if key == 'body':
- callable_ = self.template.module.render
- else:
- try:
- callable_ = self.template.get_def(key).callable_
- except AttributeError:
- callable_ = None
- if callable_ is not None:
+ try:
+ callable_ = self.template.get_def(key).callable_
return lambda *args, **kwargs:callable_(self.context, *args, **kwargs)
+ except AttributeError:
+ pass
if self._module is not None:
try:
callable_ = getattr(self._module, key)
@@ -252,14 +253,16 @@ def _render(template, callable_, args, data, as_unicode=False):
_render_context(template, callable_, context, *args, **kwargs)
return context.pop_buffer().getvalue()
-def _render_context(template, callable_, context, *args, **kwargs):
+def _render_context(tmpl, callable_, context, *args, **kwargs):
+ import mako.template as template
# create polymorphic 'self' namespace for this template with possibly updated context
- (inherit, lclcontext) = _populate_self_namespace(context, template)
- if callable_.__name__ == 'render':
+ if not isinstance(tmpl, template.DefTemplate):
# if main render method, call from the base of the inheritance stack
+ (inherit, lclcontext) = _populate_self_namespace(context, tmpl)
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
else:
# otherwise, call the actual rendering method specified
+ (inherit, lclcontext) = _populate_self_namespace(context, tmpl.parent)
_exec_template(callable_, context, args=args, kwargs=kwargs)
def _exec_template(callable_, context, args=None, kwargs=None):
diff --git a/lib/mako/template.py b/lib/mako/template.py
index 5971742..9dd895c 100644
--- a/lib/mako/template.py
+++ b/lib/mako/template.py
@@ -72,7 +72,7 @@ class Template(object):
self.module = module
self.filename = filename
- self.callable_ = self.module.render
+ self.callable_ = self.module.render_body
self.format_exceptions = format_exceptions
self.error_handler = error_handler
self.lookup = lookup