summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HISTORY.md1
-rw-r--r--pystache/view.py3
-rw-r--r--tests/test_view.py7
3 files changed, 11 insertions, 0 deletions
diff --git a/HISTORY.md b/HISTORY.md
index 2ab792d..d533662 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -1,6 +1,7 @@
## 0.2.0 (2009-11-16)
* Add support for using non-callables as View attributes. [joshthecoder]
+* Allow using View instances as attributes. [joshthecoder]
## 0.1.1 (2009-11-13)
diff --git a/pystache/view.py b/pystache/view.py
index f1fdcaa..a7a7de2 100644
--- a/pystache/view.py
+++ b/pystache/view.py
@@ -89,3 +89,6 @@ class View(object):
def render(self):
template = self.load_template()
return Template(template, self).render()
+
+ def __str__(self):
+ return self.render()
diff --git a/tests/test_view.py b/tests/test_view.py
index 8e1554e..a32fd2e 100644
--- a/tests/test_view.py
+++ b/tests/test_view.py
@@ -26,6 +26,13 @@ class TestView(unittest.TestCase):
view.thing = '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):
self.assertEquals(ComplexView().render(), """<h1>Colors</h1>
<ul>