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
21ab97cd
Commit
21ab97cd
authored
Apr 29, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed issue #113: "Section lambdas mistakenly pushed onto context stack"
parent
2adac861
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
2 deletions
+42
-2
HISTORY.rst
+2
-1
pystache/renderengine.py
+6
-1
pystache/tests/test_renderengine.py
+34
-0
No files found.
HISTORY.rst
View file @
21ab97cd
...
...
@@ -4,7 +4,8 @@ History
0.6.0 (TBD)
-----------
* Falsey values now coerced to strings using str().
* Bugfix: falsey values now coerced to strings using str().
* Bugfix: section-lambda return values no longer pushed onto context stack.
0.5.1 (2012-04-24)
------------------
...
...
pystache/renderengine.py
View file @
21ab97cd
...
...
@@ -161,7 +161,12 @@ class RenderEngine(object):
# TODO: should we check the arity?
template
=
data
(
template
)
parsed_template
=
self
.
_parse
(
template
,
delimiters
=
delims
)
data
=
[
data
]
# Lambdas special case section rendering and bypass pushing
# the data value onto the context stack. Also see--
#
# https://github.com/defunkt/pystache/issues/113
#
return
parsed_template
.
render
(
context
)
else
:
# The cleanest, least brittle way of determining whether
# something supports iteration is by trying to call iter() on it:
...
...
pystache/tests/test_renderengine.py
View file @
21ab97cd
...
...
@@ -501,6 +501,40 @@ class RenderTests(unittest.TestCase, AssertStringMixin):
context
=
{
'person'
:
'Mom'
,
'test'
:
(
lambda
text
:
text
+
" :)"
)}
self
.
_assert_render
(
u'Hi Mom :)'
,
template
,
context
)
def
test_section__lambda__not_on_context_stack
(
self
):
"""
Check that section lambdas are not pushed onto the context stack.
Even though the sections spec says that section data values should be
pushed onto the context stack prior to rendering, this does not apply
to lambdas. Lambdas obey their own special case.
This test case is equivalent to a test submitted to the Mustache spec here:
https://github.com/mustache/spec/pull/47 .
"""
context
=
{
'foo'
:
'bar'
,
'lambda'
:
(
lambda
text
:
"{{.}}"
)}
template
=
'{{#foo}}{{#lambda}}blah{{/lambda}}{{/foo}}'
self
.
_assert_render
(
u'bar'
,
template
,
context
)
def
test_section__lambda__no_reinterpolation
(
self
):
"""
Check that section lambda return values are not re-interpolated.
This test is a sanity check that the rendered lambda return value
is not re-interpolated as could be construed by reading the
section part of the Mustache spec.
This test case is equivalent to a test submitted to the Mustache spec here:
https://github.com/mustache/spec/pull/47 .
"""
template
=
'{{#planet}}{{#lambda}}dot{{/lambda}}{{/planet}}'
context
=
{
'planet'
:
'Earth'
,
'dot'
:
'~{{.}}~'
,
'lambda'
:
(
lambda
text
:
"#{{
%
s}}#"
%
text
)}
self
.
_assert_render
(
u'#~{{.}}~#'
,
template
,
context
)
def
test_comment__multiline
(
self
):
"""
Check that multiline comments are permitted.
...
...
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