diff --git a/pystache/template.py b/pystache/template.py index 0ed3afc..a457945 100644 --- a/pystache/template.py +++ b/pystache/template.py @@ -58,10 +58,9 @@ class Template(object): section, section_name, inner = match.group(0, 1, 2) section_name = section_name.strip() - it = self.view.get(section_name, None) replacer = '' - + # Callable if it and isinstance(it, collections.Callable): replacer = it(inner) @@ -73,6 +72,10 @@ class Template(object): elif it and hasattr(it, '__iter__'): if section[2] != '^': replacer = self._render_list(inner, it) + # Other objects + elif it and isinstance(it, object): + if section[2] != '^': + replacer = self._render_dictionary(inner, it) # Falsey and Negated or Truthy and Not Negated elif (not it and section[2] == '^') or (it and section[2] != '^'): replacer = inner diff --git a/tests/test_view.py b/tests/test_view.py index f2a87ff..c4d32fd 100644 --- a/tests/test_view.py +++ b/tests/test_view.py @@ -6,6 +6,9 @@ from examples.complex_view import ComplexView from examples.lambdas import Lambdas from examples.inverted import Inverted +class Thing(object): + pass + class TestView(unittest.TestCase): def test_basic(self): view = Simple("Hi {{thing}}!", { 'thing': 'world' }) @@ -86,11 +89,14 @@ class TestView(unittest.TestCase): view = Inverted() self.assertEquals(view.render(), """one, two, three, empty list""") - # def test_accessing_properties_on_parent_view(self): - # view = Simple(context={'child':child}) - # view.template = '{{#child}}{{#t}}{{thing}}{{/t}}{{/child}}' - # - # self.assertEquals(view.render(), 'pizza1') + def test_accessing_properties_on_parent_object_from_child_objects(self): + parent = Thing() + parent.this = 'derp' + parent.children = [Thing()] + view = Simple(context={'parent': parent}) + view.template = "{{#parent}}{{#children}}{{this}}{{/children}}{{/parent}}" + + self.assertEquals(view.render(), 'derp') if __name__ == '__main__': unittest.main()