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
feb339da
Commit
feb339da
authored
Mar 08, 2011
by
Mike O'Toole
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding support for implicit iterators
parent
442f84dd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
3 deletions
+23
-3
pystache/template.py
+7
-3
tests/test_pystache.py
+16
-0
No files found.
pystache/template.py
View file @
feb339da
...
...
@@ -68,7 +68,7 @@ class Template(object):
tag
=
r"
%(otag)
s(#|=|&|!|>|\{)?(.+?)\1?
%(ctag)
s+"
self
.
tag_re
=
re
.
compile
(
tag
%
tags
)
def
render_sections
(
self
,
template
,
context
):
"""Expands sections."""
while
1
:
...
...
@@ -121,7 +121,10 @@ class Template(object):
"""Given a tag name and context, finds, escapes, and renders the tag."""
raw
=
get_or_attr
(
context
,
tag_name
,
''
)
if
not
raw
and
raw
is
not
0
:
return
''
if
tag_name
==
'.'
:
raw
=
context
else
:
return
''
return
cgi
.
escape
(
unicode
(
raw
))
@modifier
(
'!'
)
...
...
@@ -151,4 +154,4 @@ class Template(object):
"""Changes the Mustache delimiter."""
self
.
otag
,
self
.
ctag
=
tag_name
.
split
(
' '
)
self
.
compile_regexps
()
return
''
return
''
\ No newline at end of file
tests/test_pystache.py
View file @
feb339da
...
...
@@ -78,6 +78,22 @@ class TestPystache(unittest.TestCase):
<li>Chris</li><li>Tom</li><li>PJ</li>
</ul>
"""
)
def
test_implicit_iterator
(
self
):
template
=
"""
<ul>
{{#users}}
<li>{{.}}</li>
{{/users}}
</ul>
"""
context
=
{
'users'
:
[
'Chris'
,
'Tom'
,
'PJ'
]
}
ret
=
pystache
.
render
(
template
,
context
)
self
.
assertEquals
(
ret
,
"""
<ul>
<li>Chris</li><li>Tom</li><li>PJ</li>
</ul>
"""
)
if
__name__
==
'__main__'
:
unittest
.
main
()
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