Commit c9dcb076 by Carl Whittaker

Merge branch 'master' into development

Conflicts:
	examples/inverted.py
	pystache/template.py
	tests/test_pystache.py
	tests/test_view.py
parents 172ad891 2a4270e1
......@@ -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 []
......@@ -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))
......
......@@ -68,6 +68,12 @@ class TestPystache(unittest.TestCase):
context = { 'users': [ {'name': 'Chris'}, {'name': 'Tom'}, {'name': 'PJ'} ] }
ret = pystache.render(template, context)
self.assertEquals(ret, """<ul><li>Chris</li><li>Tom</li><li>PJ</li></ul>""")
def test_implicit_iterator(self):
template = """<ul>{{#users}}<li>{{.}}</li>{{/users}}</ul>"""
context = { 'users': [ 'Chris', 'Tom','PJ' ] }
ret = pystache.render(template, context)
self.assertEquals(ret, """<ul><li>Chris</li><li>Tom</li><li>PJ</li></ul>""")
if __name__ == '__main__':
unittest.main()
......@@ -4,7 +4,7 @@ import pystache
from examples.simple import Simple
from examples.complex_view import ComplexView
from examples.lambdas import Lambdas
from examples.inverted import Inverted
from examples.inverted import Inverted, InvertedLists
class Thing(object):
pass
......@@ -104,5 +104,9 @@ class TestView(unittest.TestCase):
self.assertEqual(view.context, {'one': '1', 'two': '2'})
def test_inverted_lists(self):
view = InvertedLists()
self.assertEquals(view.render(), """one, two, three, empty list""")
if __name__ == '__main__':
unittest.main()
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