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
15984971
Commit
15984971
authored
May 04, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved more code (partial-related code) from parser to renderengine.
parent
ebdc702f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
7 deletions
+13
-7
pystache/parser.py
+3
-5
pystache/renderengine.py
+10
-2
No files found.
pystache/parser.py
View file @
15984971
...
...
@@ -14,7 +14,6 @@ from pystache.parsed import ParsedTemplate
DEFAULT_DELIMITERS
=
(
u'{{'
,
u'}}'
)
END_OF_LINE_CHARACTERS
=
[
u'
\r
'
,
u'
\n
'
]
NON_BLANK_RE
=
re
.
compile
(
ur'^(.)'
,
re
.
M
)
def
_compile_template_re
(
delimiters
=
None
):
...
...
@@ -205,6 +204,7 @@ class Parser(object):
elif
tag_type
==
'#'
:
# TODO: move this code into RenderEngine.
section_start_index
=
end_index
parsed_section
,
section_end_index
,
end_index
=
self
.
_parse_section
(
template
,
end_index
,
tag_key
)
func
=
engine
.
_make_get_section
(
tag_key
,
parsed_section
,
self
.
_delimiters
,
...
...
@@ -212,15 +212,13 @@ class Parser(object):
elif
tag_type
==
'^'
:
# TODO: move this code into RenderEngine.
parsed_section
,
section_end_index
,
end_index
=
self
.
_parse_section
(
template
,
end_index
,
tag_key
)
func
=
engine
.
_make_get_inverse
(
tag_key
,
parsed_section
)
elif
tag_type
==
'>'
:
template
=
engine
.
resolve_partial
(
tag_key
)
# Indent before rendering.
template
=
re
.
sub
(
NON_BLANK_RE
,
leading_whitespace
+
ur'\1'
,
template
)
func
=
engine
.
_make_get_partial
(
template
)
func
=
engine
.
_make_get_partial
(
tag_key
,
leading_whitespace
)
else
:
...
...
pystache/renderengine.py
View file @
15984971
...
...
@@ -11,6 +11,9 @@ from pystache.common import is_string
from
pystache.parser
import
Parser
NON_BLANK_RE
=
re
.
compile
(
ur'^(.)'
,
re
.
M
)
def
context_get
(
stack
,
name
):
"""
Find and return a name from a ContextStack instance.
...
...
@@ -127,13 +130,18 @@ class RenderEngine(object):
return
get_escaped
def
_make_get_partial
(
self
,
template
):
def
_make_get_partial
(
self
,
tag_key
,
leading_whitespace
):
template
=
self
.
resolve_partial
(
tag_key
)
# Indent before rendering.
template
=
re
.
sub
(
NON_BLANK_RE
,
leading_whitespace
+
ur'\1'
,
template
)
def
get_partial
(
context
):
"""
Returns: a string of type unicode.
"""
# TODO:
the parsing should be done before calling this function.
# TODO:
can we do the parsing before calling this function?
return
self
.
_render
(
template
,
context
)
return
get_partial
...
...
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