Commit 1996af1c by Chris Jerdonek

Removed View from Lambdas example.

parent f5b37f72
import pystache
from pystache import TemplateSpec
def rot(s, n=13):
r = ""
......@@ -17,8 +17,10 @@ def rot(s, n=13):
def replace(subject, this='foo', with_this='bar'):
return subject.replace(this, with_this)
class Lambdas(pystache.View):
template_path = 'examples'
# This class subclasses TemplateSpec because at least one unit test
# sets the template attribute.
class Lambdas(TemplateSpec):
def replace_foo_with_bar(self, text=None):
return replace
......
......@@ -33,7 +33,10 @@ class TestSimple(unittest.TestCase, AssertStringMixin):
def test_callables(self):
view = Lambdas()
view.template = '{{#replace_foo_with_bar}}foo != bar. oh, it does!{{/replace_foo_with_bar}}'
self.assertEquals(view.render(), 'bar != bar. oh, it does!')
renderer = Renderer()
expected = renderer.render(view)
self.assertString(expected, u'bar != bar. oh, it does!')
def test_rendering_partial(self):
view = TemplatePartial()
......
......@@ -9,6 +9,7 @@ import os.path
import sys
import unittest
import examples
from examples.simple import Simple
from examples.complex import Complex
from examples.lambdas import Lambdas
......@@ -26,6 +27,9 @@ from .data.views import SampleView
from .data.views import NonAscii
EXAMPLES_DIR = os.path.dirname(examples.__file__)
class Thing(object):
pass
......@@ -94,29 +98,41 @@ class ViewTestCase(unittest.TestCase, AssertStringMixin):
</ul>""")
def test_higher_order_replace(self):
view = Lambdas()
self.assertEquals(view.render(),
'bar != bar. oh, it does!')
renderer = Renderer()
expected = renderer.render(Lambdas())
self.assertEquals(expected, 'bar != bar. oh, it does!')
def test_higher_order_rot13(self):
view = Lambdas()
view.template = '{{#rot13}}abcdefghijklm{{/rot13}}'
self.assertEquals(view.render(), 'nopqrstuvwxyz')
renderer = Renderer()
expected = renderer.render(view)
self.assertString(expected, u'nopqrstuvwxyz')
def test_higher_order_lambda(self):
view = Lambdas()
view.template = '{{#sort}}zyxwvutsrqponmlkjihgfedcba{{/sort}}'
self.assertEquals(view.render(), 'abcdefghijklmnopqrstuvwxyz')
renderer = Renderer()
expected = renderer.render(view)
self.assertString(expected, u'abcdefghijklmnopqrstuvwxyz')
def test_partials_with_lambda(self):
view = Lambdas()
view.template = '{{>partial_with_lambda}}'
self.assertEquals(view.render(), 'nopqrstuvwxyz')
renderer = Renderer(search_dirs=EXAMPLES_DIR)
expected = renderer.render(view)
self.assertEquals(expected, u'nopqrstuvwxyz')
def test_hierarchical_partials_with_lambdas(self):
view = Lambdas()
view.template = '{{>partial_with_partial_and_lambda}}'
self.assertEquals(view.render(), 'nopqrstuvwxyznopqrstuvwxyz')
renderer = Renderer(search_dirs=EXAMPLES_DIR)
expected = renderer.render(view)
self.assertString(expected, u'nopqrstuvwxyznopqrstuvwxyz')
def test_inverted(self):
renderer = Renderer()
......
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