Commit 1996af1c by Chris Jerdonek

Removed View from Lambdas example.

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