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
ce5f66ff
Commit
ce5f66ff
authored
Mar 19, 2011
by
Pieter van de Bruggen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enabling the use of lambdas for Sections.
parent
c94e2840
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
7 deletions
+15
-7
pystache/template.py
+14
-2
pystache/view.py
+1
-5
No files found.
pystache/template.py
View file @
ce5f66ff
...
...
@@ -2,27 +2,39 @@ import re
import
cgi
import
inspect
def
call
(
view
,
x
):
def
call
(
view
,
x
,
template
=
None
):
if
callable
(
x
):
(
args
,
_
,
_
,
_
)
=
inspect
.
getargspec
(
x
)
print
args
if
len
(
args
)
is
0
:
x
=
x
()
elif
len
(
args
)
is
1
and
args
[
0
]
==
'self'
:
x
=
x
(
view
)
elif
len
(
args
)
is
1
:
x
=
x
(
template
)
else
:
x
=
x
(
view
,
template
)
return
unicode
(
x
)
def
sectionTag
(
name
,
parsed
,
template
,
delims
):
def
func
(
self
):
data
=
self
.
get
(
name
)
ast
=
parsed
if
not
data
:
return
''
elif
callable
(
data
):
tmpl
=
Template
(
call
(
self
,
data
,
template
))
tmpl
.
otag
,
tmpl
.
ctag
=
delims
tmpl
.
_compile_regexps
()
ast
=
tmpl
.
_parse
()
data
=
[
data
]
elif
type
(
data
)
not
in
[
list
,
tuple
]:
data
=
[
data
]
parts
=
[]
for
element
in
data
:
self
.
context_list
.
insert
(
0
,
element
)
parts
.
append
(
''
.
join
(
map
(
call
,
[
self
]
*
len
(
parsed
),
parsed
)))
parts
.
append
(
''
.
join
(
map
(
call
,
[
self
]
*
len
(
ast
),
ast
)))
del
self
.
context_list
[
0
]
return
''
.
join
(
parts
)
...
...
pystache/view.py
View file @
ce5f66ff
...
...
@@ -35,11 +35,7 @@ class View(object):
self
.
context_list
=
[
context
]
def
get
(
self
,
attr
,
default
=
None
):
attr
=
get_or_attr
(
self
.
context_list
,
attr
,
getattr
(
self
,
attr
,
default
))
if
hasattr
(
attr
,
'__call__'
)
and
type
(
attr
)
is
UnboundMethodType
:
return
attr
()
else
:
return
attr
return
get_or_attr
(
self
.
context_list
,
attr
,
getattr
(
self
,
attr
,
default
))
def
get_template
(
self
,
template_name
):
if
not
self
.
template
:
...
...
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