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
06e29078
Commit
06e29078
authored
May 05, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work with ParsedTemplate instance instead of parse_tree list.
parent
2de83f87
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
9 deletions
+12
-9
pystache/parsed.py
+5
-2
pystache/parser.py
+7
-7
No files found.
pystache/parsed.py
View file @
06e29078
...
...
@@ -10,7 +10,7 @@ This module is meant only for internal use.
class
ParsedTemplate
(
object
):
def
__init__
(
self
,
parse_tree
):
def
__init__
(
self
):
"""
Arguments:
...
...
@@ -30,11 +30,14 @@ class ParsedTemplate(object):
* RenderEngine._make_get_section()
"""
self
.
_parse_tree
=
parse_tree
self
.
_parse_tree
=
[]
def
__repr__
(
self
):
return
"[
%
s]"
%
(
", "
.
join
([
repr
(
part
)
for
part
in
self
.
_parse_tree
]))
def
add
(
self
,
node
):
self
.
_parse_tree
.
append
(
node
)
def
render
(
self
,
context
):
"""
Returns: a string of type unicode.
...
...
pystache/parser.py
View file @
06e29078
...
...
@@ -96,7 +96,7 @@ class Parser(object):
a ParsedTemplate instance.
"""
parse
_tree
=
[]
parse
d_template
=
ParsedTemplate
()
content_end_index
,
parsed_section
=
None
,
None
...
...
@@ -111,7 +111,7 @@ class Parser(object):
before_tag
=
template
[
start_index
:
match_index
]
parse
_tree
.
appen
d
(
before_tag
)
parse
d_template
.
ad
d
(
before_tag
)
matches
=
match
.
groupdict
()
...
...
@@ -137,7 +137,7 @@ class Parser(object):
if
end_index
<
len
(
template
):
end_index
+=
template
[
end_index
]
==
'
\n
'
and
1
or
0
elif
leading_whitespace
:
parse
_tree
.
appen
d
(
leading_whitespace
)
parse
d_template
.
ad
d
(
leading_whitespace
)
match_index
+=
len
(
leading_whitespace
)
leading_whitespace
=
''
...
...
@@ -145,7 +145,7 @@ class Parser(object):
if
tag_key
!=
section_key
:
raise
ParsingError
(
"Section end tag mismatch:
%
s !=
%
s"
%
(
tag_key
,
section_key
))
return
end_index
,
match_index
,
ParsedTemplate
(
parse_tree
)
return
end_index
,
match_index
,
parsed_template
if
tag_type
in
(
'#'
,
'^'
):
start_index
,
content_end_index
,
parsed_section
=
self
.
parse
(
template
,
end_index
,
tag_key
)
...
...
@@ -155,12 +155,12 @@ class Parser(object):
node
=
self
.
_make_node
(
template
,
tag_type
,
tag_key
,
leading_whitespace
,
end_index
,
content_end_index
,
parsed_section
)
parse
_tree
.
appen
d
(
node
)
parse
d_template
.
ad
d
(
node
)
# Save the rest of the template.
parse
_tree
.
appen
d
(
template
[
start_index
:])
parse
d_template
.
ad
d
(
template
[
start_index
:])
return
ParsedTemplate
(
parse_tree
)
return
parsed_template
def
_make_node
(
self
,
template
,
tag_type
,
tag_key
,
leading_whitespace
,
section_start_index
,
section_end_index
,
parsed_section
):
...
...
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