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
28234854
Commit
28234854
authored
May 05, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed some redundant methods from RenderEngine.
parent
222e15f3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
40 deletions
+10
-40
pystache/renderengine.py
+8
-39
pystache/tests/test_renderengine.py
+2
-1
No files found.
pystache/renderengine.py
View file @
28234854
...
...
@@ -142,7 +142,7 @@ class RenderEngine(object):
"""
# TODO: can we do the parsing before calling this function?
return
self
.
_
render
(
template
,
context
)
return
self
.
render
(
template
,
context
)
return
get_partial
...
...
@@ -235,16 +235,6 @@ class RenderEngine(object):
return
get_section_value
def
_render_unicode
(
self
,
template
,
context
,
delimiters
=
None
):
"""
Render a unicode template string.
"""
parser
=
Parser
(
self
,
delimiters
=
delimiters
)
parsed_template
=
parser
.
parse
(
template
)
return
parsed_template
.
render
(
context
)
def
_render_value
(
self
,
val
,
context
,
delimiters
=
None
):
"""
Render an arbitrary value.
...
...
@@ -255,42 +245,21 @@ class RenderEngine(object):
val
=
str
(
val
)
if
type
(
val
)
is
not
unicode
:
val
=
self
.
literal
(
val
)
return
self
.
_
render
(
val
,
context
,
delimiters
)
return
self
.
render
(
val
,
context
,
delimiters
)
def
_render
(
self
,
template
,
context
,
delimiters
=
None
):
def
render
(
self
,
template
,
context_stack
,
delimiters
=
None
):
"""
Returns: a string of type unicode.
Arguments:
template: a template string of type unicode.
context: a ContextStack instance.
"""
# We keep this type-check as an added check because this method is
# called with template strings coming from potentially externally-
# supplied functions like self.literal, self.load_partial, etc.
# Beyond this point, we have much better control over the type.
if
type
(
template
)
is
not
unicode
:
raise
Exception
(
"Argument 'template' not unicode:
%
s:
%
s"
%
(
type
(
template
),
repr
(
template
)))
return
self
.
_render_unicode
(
template
,
context
,
delimiters
)
def
render
(
self
,
template
,
context
):
"""
Return a template rendered as a string with type unicode.
Render a unicode template string, and return as unicode.
Arguments:
template: a template string of type unicode (but not a proper
subclass of unicode).
context: a ContextStack instance.
context
_stack
: a ContextStack instance.
"""
# Be strict but not too strict. In other words, accept str instead
# of unicode, but don't assume anything about the encoding (e.g.
# don't use self.literal).
template
=
unicode
(
template
)
parser
=
Parser
(
self
,
delimiters
=
delimiters
)
parsed_template
=
parser
.
parse
(
template
)
return
self
.
_render_unicode
(
template
,
context
)
return
parsed_template
.
render
(
context_stack
)
pystache/tests/test_renderengine.py
View file @
28234854
...
...
@@ -96,7 +96,8 @@ class RenderTests(unittest.TestCase, AssertStringMixin, AssertExceptionMixin):
context
=
ContextStack
(
*
context
)
actual
=
engine
.
render
(
template
,
context
)
# RenderEngine.render() only accepts unicode template strings.
actual
=
engine
.
render
(
unicode
(
template
),
context
)
self
.
assertString
(
actual
=
actual
,
expected
=
expected
)
...
...
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