Skip to content

Commit

Permalink
Bugfix: Methods returning False or None are not rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Nov 27, 2009
1 parent 09ab3f9 commit e38a953
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.2.0 (2009-??-??)

* Bugfix: Methods returning False or None are not rendered
* Add support for using non-callables as View attributes. [joshthecoder]
* Allow using View instances as attributes. [joshthecoder]

Expand Down
2 changes: 1 addition & 1 deletion examples/simple.mustache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Hi {{thing}}!
Hi {{thing}}!{{blank}}
3 changes: 3 additions & 0 deletions examples/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ class Simple(pystache.View):

def thing(self):
return "pizza"

def blank(self):
pass
2 changes: 1 addition & 1 deletion pystache/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def render_tags(self, template, context):
@modifier(None)
def render_tag(self, tag_name, context):
"""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('!')
def render_comment(self, tag_name=None, context=None):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_pystache.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def test_even_less_basic(self):
ret = pystache.render(template, { 'name': 'Jon', 'thing': 'racecar' })
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):
template = "What {{! the }} what?"
ret = pystache.render(template)
Expand Down

0 comments on commit e38a953

Please sign in to comment.