diff options
author | Eric Naeseth <enaeseth@gmail.com> | 2010-01-17 07:04:01 +0800 |
---|---|---|
committer | Chris Wanstrath <chris@ozmm.org> | 2010-02-09 18:35:31 +0800 |
commit | a708d123298e592468a55247de88303448a051d2 (patch) | |
tree | 4586be615755adbe69fe8d1562164f2b1a8ca9d8 | |
parent | abfba610b2072ea801ec27b7c44f69a18c00f768 (diff) | |
download | pystache-a708d123298e592468a55247de88303448a051d2.tar.gz |
Don't render an empty string when a tag's value is 0.
-rw-r--r-- | pystache/template.py | 5 | ||||
-rw-r--r-- | tests/test_pystache.py | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/pystache/template.py b/pystache/template.py index 787304d..c942cd7 100644 --- a/pystache/template.py +++ b/pystache/template.py @@ -97,7 +97,10 @@ class Template(object): @modifier(None) def render_tag(self, tag_name, context): """Given a tag name and context, finds, escapes, and renders the tag.""" - return cgi.escape(unicode(context.get(tag_name, '') or '')) + raw = context.get(tag_name, '') + if not raw and raw is not 0: + return '' + return cgi.escape(unicode(raw)) @modifier('!') def render_comment(self, tag_name=None, context=None): diff --git a/tests/test_pystache.py b/tests/test_pystache.py index 4298180..3f21a45 100644 --- a/tests/test_pystache.py +++ b/tests/test_pystache.py @@ -27,6 +27,11 @@ class TestPystache(unittest.TestCase): ret = pystache.render(template, { 'name': 'Jon' }) self.assertEquals(ret, "I think Jon wants a , right Jon?") + def test_render_zero(self): + template = 'My value is {{value}}.' + ret = pystache.render(template, { 'value': 0 }) + self.assertEquals(ret, 'My value is 0.') + def test_comments(self): template = "What {{! the }} what?" ret = pystache.render(template) |