Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pystache_custom
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pystache_custom
Commits
1996af1c
Commit
1996af1c
authored
Apr 01, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed View from Lambdas example.
parent
f5b37f72
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
11 deletions
+32
-11
examples/lambdas.py
+5
-3
tests/test_simple.py
+4
-1
tests/test_template_spec.py
+23
-7
No files found.
examples/lambdas.py
View file @
1996af1c
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
...
...
tests/test_simple.py
View file @
1996af1c
...
@@ -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
()
...
...
tests/test_template_spec.py
View file @
1996af1c
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment