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
d2eab0f5
Commit
d2eab0f5
authored
Dec 10, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue_27' into development
parents
5f1c034d
c49c0843
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
2 deletions
+10
-2
pystache/template.py
+3
-1
tests/test_pystache.py
+7
-1
No files found.
pystache/template.py
View file @
d2eab0f5
...
...
@@ -72,7 +72,9 @@ class Template(object):
'ctag'
:
re
.
escape
(
self
.
ctag
)
}
section
=
r"
%(otag)
s[\#|^]([^\}]*)
%(ctag)
s\s*(.+?\s*)
%(otag)
s/\1
%(ctag)
s"
# The section contents include white space to comply with the spec's
# requirement that sections not alter surrounding whitespace.
section
=
r"
%(otag)
s[\#|^]([^\}]*)
%(ctag)
s(.+?)
%(otag)
s/\1
%(ctag)
s"
self
.
section_re
=
re
.
compile
(
section
%
tags
,
re
.
M
|
re
.
S
)
tag
=
r"
%(otag)
s(#|=|&|!|>|\{)?(.+?)\1?
%(ctag)
s+"
...
...
tests/test_pystache.py
View file @
d2eab0f5
...
...
@@ -68,12 +68,18 @@ class TestPystache(unittest.TestCase):
context
=
{
'users'
:
[
{
'name'
:
'Chris'
},
{
'name'
:
'Tom'
},
{
'name'
:
'PJ'
}
]
}
ret
=
pystache
.
render
(
template
,
context
)
self
.
assertEquals
(
ret
,
"""<ul><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>"""
)
# The spec says that sections should not alter surrounding whitespace.
def
test_surrounding_whitepace_not_altered
(
self
):
template
=
"first{{#spacing}} second {{/spacing}}third"
ret
=
pystache
.
render
(
template
,
{
"spacing"
:
True
})
self
.
assertEquals
(
ret
,
"first second third"
)
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