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
4ce9bf1d
Commit
4ce9bf1d
authored
Dec 18, 2011
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue_44' into development: closing issue #44
parents
ab1d2fb1
fc4882cf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
6 deletions
+36
-6
HISTORY.rst
+1
-0
pystache/template.py
+16
-6
tests/test_template.py
+19
-0
No files found.
HISTORY.rst
View file @
4ce9bf1d
...
@@ -3,6 +3,7 @@ History
...
@@ -3,6 +3,7 @@ History
Next Release (version TBD)
Next Release (version TBD)
--------------------------
--------------------------
* Bugfix: context values no longer processed as template strings. [jakearchibald]
* API change: pass the context to render to Template.render() instead of
* API change: pass the context to render to Template.render() instead of
Template.__init__(). [cjerdonek]
Template.__init__(). [cjerdonek]
* Bugfix: Passing **kwargs to Template() modified the context. [cjerdonek]
* Bugfix: Passing **kwargs to Template() modified the context. [cjerdonek]
...
...
pystache/template.py
View file @
4ce9bf1d
...
@@ -169,18 +169,28 @@ class Template(object):
...
@@ -169,18 +169,28 @@ class Template(object):
return
template
return
template
def
_render_tags
(
self
,
template
):
def
_render_tags
(
self
,
template
):
output
=
[]
while
True
:
while
True
:
match
=
self
.
tag_re
.
search
(
template
)
parts
=
self
.
tag_re
.
split
(
template
,
maxsplit
=
1
)
if
match
is
None
:
output
.
append
(
parts
[
0
])
if
len
(
parts
)
<
2
:
# Then there was no match.
break
break
tag
,
tag_type
,
tag_name
=
match
.
group
(
0
,
1
,
2
)
start
,
tag_type
,
tag_name
,
template
=
parts
tag_name
=
tag_name
.
strip
()
tag_name
=
tag_name
.
strip
()
func
=
self
.
modifiers
[
tag_type
]
func
=
self
.
modifiers
[
tag_type
]
replacement
=
func
(
self
,
tag_name
)
tag_value
=
func
(
self
,
tag_name
)
template
=
template
.
replace
(
tag
,
replacement
)
return
template
# Appending the tag value to the output prevents treating the
# value as a template string (bug: issue #44).
output
.
append
(
tag_value
)
output
=
""
.
join
(
output
)
return
output
def
_render_dictionary
(
self
,
template
,
context
):
def
_render_dictionary
(
self
,
template
,
context
):
self
.
context
.
push
(
context
)
self
.
context
.
push
(
context
)
...
...
tests/test_template.py
View file @
4ce9bf1d
...
@@ -82,3 +82,22 @@ class TemplateTestCase(unittest.TestCase):
...
@@ -82,3 +82,22 @@ class TemplateTestCase(unittest.TestCase):
self
.
assertTrue
(
isinstance
(
actual
,
str
))
self
.
assertTrue
(
isinstance
(
actual
,
str
))
self
.
assertEquals
(
actual
,
'Poincaré'
)
self
.
assertEquals
(
actual
,
'Poincaré'
)
def
test_render__tag_in_value
(
self
):
"""
Context values should not be treated as templates (issue #44).
"""
template
=
Template
(
'{{test}}'
)
context
=
{
'test'
:
'{{hello}}'
}
actual
=
template
.
render
(
context
)
self
.
assertEquals
(
actual
,
'{{hello}}'
)
def
test_render__section_in_value
(
self
):
"""
Context values should not be treated as templates (issue #44).
"""
template
=
Template
(
'{{test}}'
)
context
=
{
'test'
:
'{{#hello}}'
}
actual
=
template
.
render
(
context
)
self
.
assertEquals
(
actual
,
'{{#hello}}'
)
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