Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-mako
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-mako
Commits
aa84c7d5
Commit
aa84c7d5
authored
18 years ago
by
Mike Bayer
Browse files
Options
Downloads
Patches
Plain Diff
adjustments to context to support 'args'
parent
62606570
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
lib/mako/codegen.py
+1
-1
1 addition, 1 deletion
lib/mako/codegen.py
lib/mako/runtime.py
+5
-19
5 additions, 19 deletions
lib/mako/runtime.py
test/call.py
+1
-1
1 addition, 1 deletion
test/call.py
test/component.py
+1
-2
1 addition, 2 deletions
test/component.py
with
8 additions
and
23 deletions
lib/mako/codegen.py
+
1
−
1
View file @
aa84c7d5
...
...
@@ -238,7 +238,7 @@ class _GenerateRenderMethod(object):
self
.
printer
.
writeline
(
"
return
''"
)
self
.
printer
.
writeline
(
None
)
self
.
printer
.
writeline
(
"
context.push(**{%s})
"
%
(
'
,
'
.
join
([
"
%s:%s
"
%
(
repr
(
x
),
x
)
for
x
in
export
]
+
[
"'
callargs
'
:runtime.AttrDict(**{%s})
"
%
'
,
'
.
join
([
"
%s:%s
"
%
(
repr
(
x
),
x
)
for
x
in
export
])]
)
)
(
'
,
'
.
join
([
"
%s:%s
"
%
(
repr
(
x
),
x
)
for
x
in
export
])
)
)
self
.
printer
.
writeline
(
"
context.write(unicode(%s))
"
%
node
.
attributes
[
'
expr
'
])
self
.
printer
.
writeline
(
"
context.pop()
"
)
...
...
This diff is collapsed.
Click to expand it.
lib/mako/runtime.py
+
5
−
19
View file @
aa84c7d5
...
...
@@ -16,16 +16,16 @@ class Context(object):
self
.
stack
=
[
data
]
# the Template instance currently rendering with this context.
self
.
with_template
=
template
class
AttrFacade
(
object
):
def
__getattr__
(
s
,
key
):
return
self
.
stack
[
-
1
][
key
]
data
.
setdefault
(
'
args
'
,
AttrFacade
())
def
__getitem__
(
self
,
key
):
return
self
.
stack
[
-
1
][
key
]
def
__setitem__
(
self
,
key
,
value
):
self
.
stack
[
-
1
][
key
]
=
value
def
get
(
self
,
key
,
default
=
None
):
return
self
.
stack
[
-
1
].
get
(
key
,
default
)
def
write
(
self
,
string
):
self
.
buffer
.
write
(
string
)
def
update
(
self
,
**
args
):
self
.
stack
[
-
1
].
update
(
args
)
def
push
(
self
,
**
args
):
x
=
self
.
stack
[
-
1
].
copy
()
x
.
update
(
args
)
...
...
@@ -34,7 +34,7 @@ class Context(object):
self
.
stack
.
pop
()
def
locals_
(
self
,
d
):
c
=
Context
(
self
.
with_template
,
self
.
buffer
,
**
self
.
stack
[
-
1
])
c
.
update
(
**
d
)
c
.
stack
[
-
1
].
update
(
**
d
)
return
c
class
Undefined
(
object
):
...
...
@@ -43,20 +43,6 @@ class Undefined(object):
raise
NameError
(
"
Undefined
"
)
UNDEFINED
=
Undefined
()
class
AttrDict
(
object
):
"""
dictionary facade providing getattr access
"""
def
__init__
(
self
,
**
data
):
self
.
data
=
data
def
__getattr__
(
self
,
key
):
return
self
.
data
[
key
]
def
__getitem__
(
self
,
key
):
return
self
.
data
[
key
]
def
__setitem__
(
self
,
key
,
value
):
self
.
data
[
key
]
=
value
def
__iter__
(
self
):
return
self
.
data
.
keys
()
def
keys
(
self
):
return
self
.
data
.
keys
()
class
Namespace
(
object
):
"""
provides access to collections of rendering methods, which can be local, from other templates, or from imported modules
"""
...
...
This diff is collapsed.
Click to expand it.
test/call.py
+
1
−
1
View file @
aa84c7d5
...
...
@@ -31,7 +31,7 @@ class CallTest(unittest.TestCase):
</%component>
<%component name=
"
foo
"
>
foo calling comp1: ${
call
args.comp1()}
foo calling comp1: ${args.comp1()}
foo calling body: ${body()}
</%component>
...
...
This diff is collapsed.
Click to expand it.
test/component.py
+
1
−
2
View file @
aa84c7d5
...
...
@@ -193,7 +193,6 @@ class ScopeTest(unittest.TestCase):
<%component name=
"
b
"
>
<%
x = 10
context[
'
x
'
] = x
%>
b. x is ${x}. ${a()}
...
...
@@ -203,7 +202,7 @@ class ScopeTest(unittest.TestCase):
</%component>
${enclosing()}
"""
)
assert
flatten_result
(
t
.
render
(
x
=
5
))
==
"
b. x is 10. a: x is
10
"
assert
flatten_result
(
t
.
render
(
x
=
5
))
==
"
b. x is 10. a: x is
5
"
def
test_scope_nine
(
self
):
"""
test that
'
enclosing scope
'
doesnt get exported to other templates
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment