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
13d24c44
Commit
13d24c44
authored
Apr 29, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed issue #114: "List of lambdas not processed correctly for sections"
parent
9da8d181
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
16 deletions
+37
-16
HISTORY.rst
+3
-1
pystache/renderengine.py
+34
-15
No files found.
HISTORY.rst
View file @
13d24c44
...
...
@@ -5,7 +5,9 @@ History
-----------
* Bugfix: falsey values now coerced to strings using str().
* Bugfix: section-lambda return values no longer pushed onto context stack.
* Bugfix: issue #113: lambda return values for sections no longer pushed
onto context stack.
* Bugfix: issue #114: lists of lambdas for sections were not rendered.
0.5.1 (2012-04-24)
------------------
...
...
pystache/renderengine.py
View file @
13d24c44
...
...
@@ -137,6 +137,7 @@ class RenderEngine(object):
# TODO: is there a bug because we are not using the same
# logic as in _get_string_value()?
data
=
context
.
get
(
name
)
# Per the spec, lambdas in inverted sections are considered truthy.
if
data
:
return
u''
return
parsed_template
.
render
(
context
)
...
...
@@ -155,21 +156,19 @@ class RenderEngine(object):
template
=
template_
parsed_template
=
parsed_template_
data
=
context
.
get
(
name
)
# From the spec:
#
# If the data is not of a list type, it is coerced into a list
# as follows: if the data is truthy (e.g. `!!data == true`),
# use a single-element list containing the data, otherwise use
# an empty list.
#
if
not
data
:
data
=
[]
elif
callable
(
data
):
# TODO: should we check the arity?
template
=
data
(
template
)
parsed_template
=
self
.
_parse
(
template
,
delimiters
=
delims
)
# 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
# s
omething s
upports iteration is by trying to call iter() on it:
# The
least brittle way to determine whether something
# supports iteration is by trying to call iter() on it:
#
# http://docs.python.org/library/functions.html#iter
#
...
...
@@ -183,14 +182,34 @@ class RenderEngine(object):
# Then the value does not support iteration.
data
=
[
data
]
else
:
# We treat the value as a list (but do not treat strings
# and dicts as lists).
if
isinstance
(
data
,
(
basestring
,
dict
)):
# Do not treat strings and dicts (which are iterable) as lists.
data
=
[
data
]
# Otherwise,
leave it alone
.
# Otherwise,
treat the value as a list
.
parts
=
[]
for
element
in
data
:
if
callable
(
element
):
# Lambdas special case section rendering and bypass pushing
# the data value onto the context stack. From the spec--
#
# When used as the data value for a Section tag, the
# lambda MUST be treatable as an arity 1 function, and
# invoked as such (passing a String containing the
# unprocessed section contents). The returned value
# MUST be rendered against the current delimiters, then
# interpolated in place of the section.
#
# Also see--
#
# https://github.com/defunkt/pystache/issues/113
#
# TODO: should we check the arity?
new_template
=
element
(
template
)
parsed_template
=
self
.
_parse
(
new_template
,
delimiters
=
delims
)
parts
.
append
(
parsed_template
.
render
(
context
))
continue
context
.
push
(
element
)
parts
.
append
(
parsed_template
.
render
(
context
))
context
.
pop
()
...
...
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