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
c1a96ac3
Commit
c1a96ac3
authored
Jan 02, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplified call() even further.
parent
b222ce48
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
23 deletions
+38
-23
pystache/renderengine.py
+38
-23
No files found.
pystache/renderengine.py
View file @
c1a96ac3
...
...
@@ -17,8 +17,10 @@ DEFAULT_TAG_CLOSING = '}}'
END_OF_LINE_CHARACTERS
=
[
'
\r
'
,
'
\n
'
]
def
call
(
val
,
view
):
def
call
(
val
,
context
):
"""
Returns: a string of type unicode.
Arguments:
val: the argument val can be any of the following:
...
...
@@ -28,53 +30,48 @@ def call(val, view):
* RenderEngine._make_get_literal():
Args: context
Returns: unicode
* RenderEngine._make_get_escaped():
Args: context
Returns: unicode
* RenderEngine._make_get_partial()
Args: context
Returns: unicode
* RenderEngine._make_get_section()
Args: context
Returns: unicode
* _make_get_inverse()
Args: context
Returns: unicode
"""
if
callable
(
val
):
(
args
,
_
,
_
,
_
)
=
inspect
.
getargspec
(
val
)
args_count
=
len
(
args
)
if
not
isinstance
(
val
,
types
.
FunctionType
):
# Then val is an instance method. Subtract one from the
# argument count because Python will automatically prepend
# self to the argument list when calling.
args_count
-=
1
if
args_count
is
0
:
val
=
val
()
else
:
val
=
val
(
view
)
if
val
is
None
:
val
=
''
val
=
val
(
context
)
return
unicode
(
val
)
return
val
def
render_parse_tree
(
parse_tree
,
context
):
"""
Convert a parse-tree into a string
.
Returns: a string of type unicode
.
"""
get_string
=
lambda
val
:
call
(
val
,
context
)
parts
=
map
(
get_string
,
parse_tree
)
return
''
.
join
(
parts
)
s
=
''
.
join
(
parts
)
return
unicode
(
s
)
def
_make_get_inverse
(
name
,
parsed
):
def
get_inverse
(
context
):
"""
Returns a string with type unicode.
"""
data
=
context
.
get
(
name
)
if
data
:
return
''
return
u
''
return
render_parse_tree
(
parsed
,
context
)
return
get_inverse
...
...
@@ -166,6 +163,8 @@ class RenderEngine(object):
def
_render_template
(
self
,
template
,
context
):
"""
Returns: a string of type unicode.
Arguments:
template: template string
...
...
@@ -256,6 +255,10 @@ class RenderEngine(object):
def
_make_get_literal
(
self
,
name
):
def
get_literal
(
context
):
"""
Returns: a string of type unicode.
"""
s
=
self
.
_get_string_value
(
context
,
name
)
s
=
self
.
literal
(
s
)
return
s
...
...
@@ -266,6 +269,10 @@ class RenderEngine(object):
get_literal
=
self
.
_make_get_literal
(
name
)
def
get_escaped
(
context
):
"""
Returns: a string of type unicode.
"""
s
=
self
.
_get_string_value
(
context
,
name
)
s
=
self
.
escape
(
s
)
return
s
...
...
@@ -274,6 +281,10 @@ class RenderEngine(object):
def
_make_get_partial
(
self
,
name
,
indentation
=
''
):
def
get_partial
(
context
):
"""
Returns: a string of type unicode.
"""
nonblank
=
re
.
compile
(
r'^(.)'
,
re
.
M
)
template
=
self
.
load_partial
(
name
)
# Indent before rendering.
...
...
@@ -284,6 +295,10 @@ class RenderEngine(object):
def
_make_get_section
(
self
,
name
,
parse_tree_
,
template_
,
delims
):
def
get_section
(
context
):
"""
Returns: a string of type unicode.
"""
template
=
template_
parse_tree
=
parse_tree_
data
=
context
.
get
(
name
)
...
...
@@ -303,7 +318,7 @@ class RenderEngine(object):
parts
.
append
(
render_parse_tree
(
parse_tree
,
context
))
context
.
pop
()
return
''
.
join
(
parts
)
return
unicode
(
''
.
join
(
parts
)
)
return
get_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