Skip to content
Snippets Groups Projects
Commit 94bd8111 authored by Mike Bayer's avatar Mike Bayer
Browse files

trying to make autohandler extension look better. theyre going to want a tag....

parent afe036c1
No related branches found
No related tags found
No related merge requests found
...@@ -134,7 +134,7 @@ class _GenerateRenderMethod(object): ...@@ -134,7 +134,7 @@ class _GenerateRenderMethod(object):
self.printer.write_indented_block(n.text) self.printer.write_indented_block(n.text)
def write_inherit(self, node): def write_inherit(self, node):
self.printer.writeline("def _mako_inherit(context):") self.printer.writeline("def _mako_inherit(template, context):")
self.printer.writeline("_mako_generate_namespaces(context)") self.printer.writeline("_mako_generate_namespaces(context)")
self.printer.writeline("return runtime.inherit_from(context, %s, _template_filename)" % (node.parsed_attributes['file'])) self.printer.writeline("return runtime.inherit_from(context, %s, _template_filename)" % (node.parsed_attributes['file']))
self.printer.writeline(None) self.printer.writeline(None)
......
"""adds autohandler functionality to Mako templates""" """adds autohandler functionality to Mako templates.
requires that the TemplateLookup class is used with templates.
"""
import posixpath, os, re import posixpath, os, re
def autohandler(context, _template_filename, name='autohandler'): def autohandler(template, context, name='autohandler'):
lookup = context.lookup lookup = context.lookup
_template_filename = template.module._template_filename
if not lookup.filesystem_checks: if not lookup.filesystem_checks:
try: try:
return lookup._uri_cache[(autohandler, _template_filename, name)] return lookup._uri_cache[(autohandler, _template_filename, name)]
......
...@@ -175,7 +175,7 @@ def inherit_from(context, uri, calling_filename): ...@@ -175,7 +175,7 @@ def inherit_from(context, uri, calling_filename):
context._data['parent'] = lclcontext._data['local'] = ih.inherits context._data['parent'] = lclcontext._data['local'] = ih.inherits
callable_ = getattr(template.module, '_mako_inherit', None) callable_ = getattr(template.module, '_mako_inherit', None)
if callable_ is not None: if callable_ is not None:
ret = callable_(lclcontext) ret = callable_(template, lclcontext)
if ret: if ret:
return ret return ret
...@@ -197,7 +197,7 @@ def _populate_self_namespace(context, template, self_ns=None): ...@@ -197,7 +197,7 @@ def _populate_self_namespace(context, template, self_ns=None):
self_ns = Namespace('self:%s' % template.description, context, template=template, populate_self=False) self_ns = Namespace('self:%s' % template.description, context, template=template, populate_self=False)
context._data['self'] = context._data['local'] = self_ns context._data['self'] = context._data['local'] = self_ns
if hasattr(template.module, '_mako_inherit'): if hasattr(template.module, '_mako_inherit'):
ret = template.module._mako_inherit(context) ret = template.module._mako_inherit(template, context)
if ret: if ret:
return ret return ret
return (template.callable_, context) return (template.callable_, context)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment