diff --git a/CHANGES b/CHANGES index 75c1543ae2f0708f3ede9f62687ab88dede8fad1..63410aa2165ccc70d6bbb221849d19ed329c4d90 100644 --- a/CHANGES +++ b/CHANGES @@ -6,7 +6,10 @@ existed anyway) - fixed bug where local.get_namespace() could put an incorrect "self" in the current context - +- fixed another namespace bug where the namespace functions + did not have access to the correct context containing + their 'self' and 'parent' + 0.1.9 - filters.Decode filter can also accept a non-basestring object and will call str() + unicode() on it [ticket:47] diff --git a/lib/mako/runtime.py b/lib/mako/runtime.py index d08a20982205fbb32ea8079fede72e6eb279e1d8..dd4aade6ff2402ae503e7870502159e3104ca276 100644 --- a/lib/mako/runtime.py +++ b/lib/mako/runtime.py @@ -120,7 +120,7 @@ class Namespace(object): else: self.callables = None if populate_self and self.template is not None: - (lclcallable, self.context) = _populate_self_namespace(context, self.template, self_ns=self) + (lclcallable, lclcontext) = _populate_self_namespace(context, self.template, self_ns=self) module = property(lambda s:s._module or s.template.module) filename = property(lambda s:s._module and s._module.__file__ or s.template.filename) diff --git a/test/namespace.py b/test/namespace.py index 9be445cd96adebe718dbe104e9f86e329aef206c..36b811b49d5975f2aa62bf951c8e9db9212bd755 100644 --- a/test/namespace.py +++ b/test/namespace.py @@ -282,6 +282,40 @@ class NamespaceTest(unittest.TestCase): "this is index", "this is ns.html->bar" ] + + def test_inheritance_two(self): + collection = lookup.TemplateLookup() + collection.put_string("base.html", """ + <%def name="foo()"> + base.foo + </%def> + + <%def name="bat()"> + base.bat + </%def> +""") + collection.put_string("lib.html", """ + <%inherit file="base.html"/> + <%def name="bar()"> + lib.bar + ${parent.foo()} + ${self.foo()} + ${parent.bat()} + ${self.bat()} + </%def> + + <%def name="foo()"> + lib.foo + </%def> + + """) + + collection.put_string("front.html", """ + <%namespace name="lib" file="lib.html"/> + ${lib.bar()} + """) + + assert result_lines(collection.get_template("front.html").render()) == ['lib.bar', 'base.foo', 'lib.foo', 'base.bat', 'base.bat'] def test_ccall(self): collection = lookup.TemplateLookup()