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
1979c2bb
Commit
1979c2bb
authored
Jan 01, 2012
by
Chris Jerdonek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved functions to top of renderengine.py.
parent
27af8b15
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
53 deletions
+57
-53
pystache/renderengine.py
+57
-53
No files found.
pystache/renderengine.py
View file @
1979c2bb
...
...
@@ -25,6 +25,63 @@ except ImportError:
return
hasattr
(
it
,
'__call__'
)
# TODO: what are the possibilities for val?
def
call
(
val
,
view
,
template
=
None
):
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
()
elif
args_count
is
1
and
args
[
0
]
in
[
'self'
,
'context'
]:
val
=
val
(
view
)
elif
args_count
is
1
:
val
=
val
(
template
)
else
:
val
=
val
(
view
,
template
)
if
callable
(
val
):
val
=
val
(
template
)
if
val
is
None
:
val
=
''
return
unicode
(
val
)
def
render_parse_tree
(
parse_tree
,
context
,
template
):
"""
Convert a parse-tree into a string.
"""
get_string
=
lambda
val
:
call
(
val
,
context
,
template
)
parts
=
map
(
get_string
,
parse_tree
)
return
''
.
join
(
parts
)
def
inverseTag
(
name
,
parsed
,
template
,
delims
):
def
func
(
self
):
data
=
self
.
get
(
name
)
if
data
:
return
''
return
render_parse_tree
(
parsed
,
self
,
delims
)
return
func
class
EndOfSection
(
Exception
):
def
__init__
(
self
,
parse_tree
,
template
,
position
):
self
.
parse_tree
=
parse_tree
self
.
template
=
template
self
.
position
=
position
class
RenderEngine
(
object
):
"""
...
...
@@ -276,59 +333,6 @@ class RenderEngine(object):
return
output
# TODO: what are the possibilities for val?
def
call
(
val
,
view
,
template
=
None
):
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
()
elif
args_count
is
1
and
args
[
0
]
in
[
'self'
,
'context'
]:
val
=
val
(
view
)
elif
args_count
is
1
:
val
=
val
(
template
)
else
:
val
=
val
(
view
,
template
)
if
callable
(
val
):
val
=
val
(
template
)
if
val
is
None
:
val
=
''
return
unicode
(
val
)
def
render_parse_tree
(
parse_tree
,
context
,
template
):
"""
Convert a parse-tree into a string.
"""
get_string
=
lambda
val
:
call
(
val
,
context
,
template
)
parts
=
map
(
get_string
,
parse_tree
)
return
''
.
join
(
parts
)
def
inverseTag
(
name
,
parsed
,
template
,
delims
):
def
func
(
self
):
data
=
self
.
get
(
name
)
if
data
:
return
''
return
render_parse_tree
(
parsed
,
self
,
delims
)
return
func
class
EndOfSection
(
Exception
):
def
__init__
(
self
,
parse_tree
,
template
,
position
):
self
.
parse_tree
=
parse_tree
self
.
template
=
template
self
.
position
=
position
class
Template
(
object
):
tag_re
=
None
otag
,
ctag
=
'{{'
,
'}}'
...
...
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