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
cae37b1f
Commit
cae37b1f
authored
Mar 10, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue-93' into development (iterable section values)
parents
f7df3412
50deed80
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletions
+24
-1
pystache/renderengine.py
+1
-1
tests/test_renderengine.py
+23
-0
No files found.
pystache/renderengine.py
View file @
cae37b1f
...
...
@@ -168,7 +168,7 @@ class RenderEngine(object):
template
=
data
(
template
)
parsed_template
=
self
.
_parse
(
template
,
delimiters
=
delims
)
data
=
[
data
]
elif
type
(
data
)
not
in
[
list
,
tuple
]
:
elif
not
hasattr
(
data
,
'__iter__'
)
or
isinstance
(
data
,
dict
)
:
data
=
[
data
]
parts
=
[]
...
...
tests/test_renderengine.py
View file @
cae37b1f
...
...
@@ -376,6 +376,29 @@ class RenderTests(unittest.TestCase):
context
=
{
'test'
:
(
lambda
text
:
'Hi
%
s'
%
text
)}
self
.
_assert_render
(
'Hi Mom'
,
template
,
context
)
def
test_section__iterable
(
self
):
"""
Check that objects supporting iteration (aside from dicts) behave like lists.
"""
template
=
'{{#iterable}}{{.}}{{/iterable}}'
context
=
{
'iterable'
:
(
i
for
i
in
range
(
3
))}
# type 'generator'
self
.
_assert_render
(
'012'
,
template
,
context
)
context
=
{
'iterable'
:
xrange
(
4
)}
# type 'xrange'
self
.
_assert_render
(
'0123'
,
template
,
context
)
d
=
{
'foo'
:
0
,
'bar'
:
0
}
# We don't know what order of keys we'll be given, but from the
# Python documentation:
# "If items(), keys(), values(), iteritems(), iterkeys(), and
# itervalues() are called with no intervening modifications to
# the dictionary, the lists will directly correspond."
expected
=
''
.
join
(
d
.
keys
())
context
=
{
'iterable'
:
d
.
iterkeys
()}
# type 'dictionary-keyiterator'
self
.
_assert_render
(
expected
,
template
,
context
)
def
test_section__lambda__tag_in_output
(
self
):
"""
Check that callable output is treated as a template string (issue #46).
...
...
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