diff --git a/examples/inverted.py b/examples/inverted.py index daa6fca..e0f7aaf 100644 --- a/examples/inverted.py +++ b/examples/inverted.py @@ -16,4 +16,13 @@ class Inverted(pystache.View): return [] def populated_list(self): - return ['some_value'] \ No newline at end of file + return ['some_value'] + +class InvertedLists(Inverted): + template_name = 'inverted' + + def t(self): + return [0, 1, 2] + + def f(self): + return [] diff --git a/pystache/template.py b/pystache/template.py index 875f274..112219d 100644 --- a/pystache/template.py +++ b/pystache/template.py @@ -87,7 +87,7 @@ class Template(object): replacer = self._render_dictionary(inner, it) # Falsey and Negated or Truthy and Not Negated elif (not it and section[2] == '^') or (it and section[2] != '^'): - replacer = inner + replacer = self._render_dictionary(inner, it) template = template.replace(section, replacer) @@ -127,7 +127,10 @@ class Template(object): # For methods with no return value if not raw and raw is not 0: - return '' + if tag_name == '.': + raw = self.view.context_list[0] + else: + return '' return cgi.escape(unicode(raw)) diff --git a/tests/test_pystache.py b/tests/test_pystache.py index 6b82e3c..c04489b 100644 --- a/tests/test_pystache.py +++ b/tests/test_pystache.py @@ -68,6 +68,12 @@ class TestPystache(unittest.TestCase): context = { 'users': [ {'name': 'Chris'}, {'name': 'Tom'}, {'name': 'PJ'} ] } ret = pystache.render(template, context) self.assertEquals(ret, """