Commit 8954e01f by Carl Whittaker

Fixing views as attributes not being rendered before display

parent c859dfa2
......@@ -99,19 +99,15 @@ class Template(object):
from view import View
view = View(context=context)
view.template_path = self.view.template_path
view.template_encoding = self.view.template_encoding
view.parent = self.view
return Template(template, view).render()
def _render_list(self, template, listing):
from view import View
def _render_list(self, template, listing):
insides = []
for item in listing:
view = View(context=item)
view.template_path = self.view.template_path
view.template_encoding = self.view.template_encoding
view.parent = self.view
insides.append(Template(template, view).render())
insides.append(self._render_dictionary(template, item))
return ''.join(insides)
......
......@@ -20,6 +20,8 @@ class View(object):
attr = self.context.get(attr, getattr(self, attr, self._get_from_parent(attr, default)))
if hasattr(attr, '__call__') and type(attr) is UnboundMethodType:
return attr()
if hasattr(attr, 'render'):
return attr.render(encoding=self.template_encoding)
else:
return attr
......
......@@ -31,7 +31,7 @@ class TestSimple(unittest.TestCase):
view = TemplatePartial()
self.assertEquals(pystache.Template('{{>inner_partial}}', view).render(), 'Again, Welcome!')
self.assertEquals(pystache.Template('{{#looping}}{{>inner_partial}} {{/looping}}', view).render(), '''Again, Welcome! Again, Welcome! Again, Welcome!''')
self.assertEquals(pystache.Template('{{#looping}}{{>inner_partial}} {{/looping}}', view).render(), '''Again, Welcome! Again, Welcome! Again, Welcome! ''')
def test_non_existent_value_renders_blank(self):
view = Simple()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment