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
a39b16e6
Commit
a39b16e6
authored
18 years ago
by
Mike Bayer
Browse files
Options
Downloads
Patches
Plain Diff
some stuff with args
parent
a7a8c619
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/mako/codegen.py
+11
-3
11 additions, 3 deletions
lib/mako/codegen.py
test/template.py
+18
-0
18 additions, 0 deletions
test/template.py
with
29 additions
and
3 deletions
lib/mako/codegen.py
+
11
−
3
View file @
a39b16e6
...
...
@@ -83,6 +83,7 @@ class _GenerateRenderMethod(object):
# write explicit "context.get()" statements for variables that are already in the
# local namespace, that we are going to re-assign
print
"
WVD
"
,
identifiers
to_write
=
identifiers
.
declared
.
intersection
(
identifiers
.
locally_declared
)
# write "context.get()" for all variables we are going to need that arent in the namespace yet
...
...
@@ -91,6 +92,8 @@ class _GenerateRenderMethod(object):
# write closure functions for closures that we define right here
to_write
=
to_write
.
union
(
util
.
Set
([
c
.
name
for
c
in
identifiers
.
closurecomponents
if
c
.
parent
is
self
.
node
]))
to_write
=
to_write
.
difference
(
identifiers
.
argument_declared
)
for
ident
in
to_write
:
if
ident
in
comp_idents
:
comp
=
comp_idents
[
ident
]
...
...
@@ -118,9 +121,10 @@ class _GenerateRenderMethod(object):
def
write_inline_component
(
self
,
node
,
identifiers
):
namedecls
=
node
.
function_decl
.
get_argument_expressions
()
self
.
printer
.
writeline
(
"
def %s(%s):
"
%
(
node
.
name
,
"
,
"
.
join
(
namedecls
)))
print
"
INLINE NAME
"
,
node
.
name
identifiers
=
identifiers
.
branch
(
node
)
print
"
IDENTIFIERES
"
,
identifiers
# if we assign to variables in this closure, then we have to nest inside
# of another callable so that the "context" variable is copied into the local scope
make_closure
=
len
(
identifiers
.
locally_declared
)
>
0
...
...
@@ -209,6 +213,8 @@ class _Identifiers(object):
# things that are declared locally
self
.
locally_declared
=
util
.
Set
()
self
.
argument_declared
=
util
.
Set
()
# closure components that are defined in this level
self
.
closurecomponents
=
util
.
Set
()
...
...
@@ -230,6 +236,7 @@ class _Identifiers(object):
for
ident
in
node
.
declared_identifiers
():
self
.
locally_declared
.
add
(
ident
)
for
ident
in
node
.
undeclared_identifiers
():
print
"
UNDECL IDENT IN NODE
"
,
node
,
ident
if
ident
!=
'
context
'
and
ident
not
in
self
.
declared
.
union
(
self
.
locally_declared
):
self
.
undeclared
.
add
(
ident
)
...
...
@@ -245,7 +252,8 @@ class _Identifiers(object):
self
.
toplevelcomponents
.
add
(
node
)
elif
node
is
not
self
.
node
:
self
.
closurecomponents
.
add
(
node
)
self
.
check_declared
(
node
)
for
ident
in
node
.
declared_identifiers
():
self
.
argument_declared
.
add
(
ident
)
if
node
is
self
.
node
:
for
n
in
node
.
nodes
:
n
.
accept_visitor
(
self
)
...
...
This diff is collapsed.
Click to expand it.
test/template.py
+
18
−
0
View file @
a39b16e6
...
...
@@ -124,6 +124,24 @@ class NestedComponentTest(unittest.TestCase):
result
=
re
.
sub
(
r
'
[\s\n]+
'
,
'
'
,
result
).
strip
()
assert
result
==
"
hey, im hi. and heres this is foo , this is bar
"
def
test_nested_with_args
(
self
):
template
=
Template
(
"""
${a()}
<%component name=
"
a
"
>
<%component name=
"
b(x, y=2)
"
>
b x is ${x} y is ${y}
</%component>
a ${b(5)}
</%component>
"""
)
#print template.code
result
=
template
.
render
()
#print result
result
=
re
.
sub
(
r
'
[\s\n]+
'
,
'
'
,
result
).
strip
()
assert
result
==
"
a b x is 5 y is 2
"
def
test_nested_component_2
(
self
):
template
=
Template
(
"""
${a()}
...
...
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