Commit e38a953b by Chris Wanstrath

Bugfix: Methods returning False or None are not rendered

parent 09ab3f95
## 0.2.0 (2009-??-??) ## 0.2.0 (2009-??-??)
* Bugfix: Methods returning False or None are not rendered
* 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] * Allow using View instances as attributes. [joshthecoder]
......
Hi {{thing}}! Hi {{thing}}!{{blank}}
\ No newline at end of file \ No newline at end of file
...@@ -5,3 +5,6 @@ class Simple(pystache.View): ...@@ -5,3 +5,6 @@ class Simple(pystache.View):
def thing(self): def thing(self):
return "pizza" return "pizza"
def blank(self):
pass
...@@ -94,7 +94,7 @@ class Template(object): ...@@ -94,7 +94,7 @@ class Template(object):
@modifier(None) @modifier(None)
def render_tag(self, tag_name, context): def render_tag(self, tag_name, context):
"""Given a tag name and context, finds, escapes, and renders the tag.""" """Given a tag name and context, finds, escapes, and renders the tag."""
return cgi.escape(str(context.get(tag_name, ''))) return cgi.escape(str(context.get(tag_name, '') or ''))
@modifier('!') @modifier('!')
def render_comment(self, tag_name=None, context=None): def render_comment(self, tag_name=None, context=None):
......
...@@ -20,6 +20,11 @@ class TestPystache(unittest.TestCase): ...@@ -20,6 +20,11 @@ class TestPystache(unittest.TestCase):
ret = pystache.render(template, { 'name': 'Jon', 'thing': 'racecar' }) ret = pystache.render(template, { 'name': 'Jon', 'thing': 'racecar' })
self.assertEquals(ret, "I think Jon wants a racecar, right Jon?") self.assertEquals(ret, "I think Jon wants a racecar, right Jon?")
def test_ignores_misses(self):
template = "I think {{name}} wants a {{thing}}, right {{name}}?"
ret = pystache.render(template, { 'name': 'Jon' })
self.assertEquals(ret, "I think Jon wants a , right Jon?")
def test_comments(self): def test_comments(self):
template = "What {{! the }} what?" template = "What {{! the }} what?"
ret = pystache.render(template) ret = pystache.render(template)
......
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