Commit 65646c81 by Joshua Roesslein Committed by Chris Wanstrath

Allow using View instances as attributes.

parent f03c85c7
## 0.2.0 (2009-11-16) ## 0.2.0 (2009-11-16)
* Add support for using non-callables as View attributes. [joshthecoder] * Add support for using non-callables as View attributes. [joshthecoder]
* Allow using View instances as attributes. [joshthecoder]
## 0.1.1 (2009-11-13) ## 0.1.1 (2009-11-13)
......
...@@ -89,3 +89,6 @@ class View(object): ...@@ -89,3 +89,6 @@ class View(object):
def render(self): def render(self):
template = self.load_template() template = self.load_template()
return Template(template, self).render() return Template(template, self).render()
def __str__(self):
return self.render()
...@@ -26,6 +26,13 @@ class TestView(unittest.TestCase): ...@@ -26,6 +26,13 @@ class TestView(unittest.TestCase):
view.thing = 'Chris' view.thing = 'Chris'
self.assertEquals(view.render(), "Hi Chris!") self.assertEquals(view.render(), "Hi Chris!")
def test_view_instances_as_attributes(self):
other = Simple(name='chris')
other.template = '{{name}}'
view = Simple()
view.thing = other
self.assertEquals(view.render(), "Hi chris!")
def test_complex(self): def test_complex(self):
self.assertEquals(ComplexView().render(), """<h1>Colors</h1> self.assertEquals(ComplexView().render(), """<h1>Colors</h1>
<ul> <ul>
......
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