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
77697374
Commit
77697374
authored
Aug 19, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added support for applying lambda function after rendering
parent
599bb135
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
1 deletions
+38
-1
pystache_custom/parser.py
+6
-1
pystache_custom/renderengine.py
+32
-0
No files found.
pystache_custom/parser.py
View file @
77697374
...
...
@@ -41,7 +41,7 @@ def _compile_template_re(delimiters=None):
(?:
(?P<change>=) \s* (?P<delims>.+?) \s* = |
(?P<raw>{) \s* (?P<raw_name>.+?) \s* } |
(?P<tag>[
%(tag_types)
s]
?
) \s* (?P<tag_key>[\s\S]+?)
(?P<tag>[
%(tag_types)
s]
*
) \s* (?P<tag_key>[\s\S]+?)
)
\s*
%(ctag)
s
"""
%
{
'tag_types'
:
tag_types
,
'otag'
:
re
.
escape
(
delimiters
[
0
]),
'ctag'
:
re
.
escape
(
delimiters
[
1
])}
...
...
@@ -209,6 +209,11 @@ class Parser(object):
parsed_section
,
section_contents
,
end_index
=
self
.
_parse_section
(
template
,
end_index
,
tag_key
)
func
=
engine
.
_make_get_section
(
tag_key
,
parsed_section
,
section_contents
,
self
.
_delimiters
)
elif
tag_type
==
'##'
:
parsed_section
,
section_contents
,
end_index
=
self
.
_parse_section
(
template
,
end_index
,
tag_key
)
func
=
engine
.
_make_rendered_get_section
(
tag_key
,
parsed_section
,
section_contents
,
self
.
_delimiters
)
elif
tag_type
==
'^'
:
parsed_section
,
section_contents
,
end_index
=
self
.
_parse_section
(
template
,
end_index
,
tag_key
)
...
...
pystache_custom/renderengine.py
View file @
77697374
...
...
@@ -220,6 +220,38 @@ class RenderEngine(object):
return
get_section
def
_make_rendered_get_section
(
self
,
name
,
parsed_template_
,
template_
,
delims
):
def
get_section
(
context
):
template
=
template_
parsed_template
=
parsed_template_
data
=
context
.
get
(
name
)
if
not
data
:
data
=
[]
else
:
try
:
iter
(
data
)
except
TypeError
:
data
=
[
data
]
else
:
if
isinstance
(
data
,
(
basestring
,
dict
)):
data
=
[
data
]
parts
=
[]
for
element
in
data
:
if
callable
(
element
):
parts
.
append
(
element
(
parsed_template
.
render
(
context
)))
continue
context
.
push
(
element
)
parts
.
append
(
parsed_template
.
render
(
context
))
context
.
pop
()
return
unicode
(
''
.
join
(
parts
))
return
get_section
def
_parse
(
self
,
template
,
delimiters
=
None
):
"""
Parse the given template, and return a ParsedTemplate instance.
...
...
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