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
53a7f8bb
Commit
53a7f8bb
authored
18 years ago
by
Mike Bayer
Browse files
Options
Downloads
Patches
Plain Diff
more inheritance tests and turning on attribute-embedded expressions
parent
706d9657
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/mako/codegen.py
+3
-4
3 additions, 4 deletions
lib/mako/codegen.py
lib/mako/parsetree.py
+8
-5
8 additions, 5 deletions
lib/mako/parsetree.py
test/inheritance.py
+7
-3
7 additions, 3 deletions
test/inheritance.py
with
18 additions
and
12 deletions
lib/mako/codegen.py
+
3
−
4
View file @
53a7f8bb
...
...
@@ -206,7 +206,7 @@ class _GenerateRenderMethod(object):
def
visitIncludeTag
(
self
,
node
):
self
.
write_source_comment
(
node
)
self
.
printer
.
writeline
(
"
runtime.include_file(context, %s, import_symbols=%s)
"
%
(
repr
(
node
.
attributes
[
'
file
'
]
)
,
repr
(
node
.
attributes
.
get
(
'
import
'
,
False
))))
self
.
printer
.
writeline
(
"
runtime.include_file(context, %s, import_symbols=%s)
"
%
(
node
.
parsed_
attributes
[
'
file
'
],
repr
(
node
.
attributes
.
get
(
'
import
'
,
False
))))
def
visitNamespaceTag
(
self
,
node
):
self
.
write_source_comment
(
node
)
...
...
@@ -222,7 +222,7 @@ class _GenerateRenderMethod(object):
n
.
accept_visitor
(
vis
)
self
.
printer
.
writeline
(
"
return [%s]
"
%
(
'
,
'
.
join
(
export
)))
self
.
printer
.
writeline
(
None
)
self
.
printer
.
writeline
(
"
%s = runtime.Namespace(%s, context.clean_inheritance_tokens(), templateuri=%s, callables=make_namespace())
"
%
(
node
.
name
,
repr
(
node
.
name
),
repr
(
node
.
attributes
[
'
file
'
]))
)
self
.
printer
.
writeline
(
"
%s = runtime.Namespace(%s, context.clean_inheritance_tokens(), templateuri=%s, callables=make_namespace())
"
%
(
node
.
name
,
repr
(
node
.
name
),
node
.
parsed_
attributes
[
'
file
'
]))
def
visitComponentTag
(
self
,
node
):
pass
...
...
@@ -334,8 +334,7 @@ class _Identifiers(object):
for
n
in
node
.
nodes
:
n
.
accept_visitor
(
self
)
def
visitIncludeTag
(
self
,
node
):
# TODO: expressions for attributes
pass
self
.
check_declared
(
node
)
def
visitNamespaceTag
(
self
,
node
):
self
.
check_declared
(
node
)
if
node
is
self
.
node
:
...
...
This diff is collapsed.
Click to expand it.
lib/mako/parsetree.py
+
8
−
5
View file @
53a7f8bb
...
...
@@ -192,8 +192,8 @@ class Tag(Node):
for
x
in
re
.
split
(
r
'
(\${.+?})
'
,
self
.
attributes
[
key
]):
m
=
re
.
match
(
r
'
^\${(.+?)}$
'
,
x
)
if
m
:
#
code = ast.PythonCode(m.group(1), self.lineno, self.pos)
#
undeclared_identifiers = undeclared_identifiers.union(code.undeclared_identifiers)
code
=
ast
.
PythonCode
(
m
.
group
(
1
),
self
.
lineno
,
self
.
pos
)
undeclared_identifiers
=
undeclared_identifiers
.
union
(
code
.
undeclared_identifiers
)
expr
.
append
(
m
.
group
(
1
))
else
:
expr
.
append
(
repr
(
x
))
...
...
@@ -203,7 +203,12 @@ class Tag(Node):
raise
exceptions
.
CompileException
(
"
Attibute
'
%s
'
in tag
'
%s
'
does not allow embedded expressions
"
%
(
key
,
self
.
keyword
),
self
.
lineno
,
self
.
pos
)
self
.
parsed_attributes
[
key
]
=
repr
(
self
.
attributes
[
key
])
else
:
raise
exceptions
.
CompileException
(
"
Invalid attribute for tag
'
%s
'
:
'
%s
'"
%
(
self
.
keyword
,
key
),
self
.
lineno
,
self
.
pos
)
raise
exceptions
.
CompileException
(
"
Invalid attribute for tag
'
%s
'
:
'
%s
'"
%
(
self
.
keyword
,
key
),
self
.
lineno
,
self
.
pos
)
self
.
expression_undeclared_identifiers
=
undeclared_identifiers
def
declared_identifiers
(
self
):
return
[]
def
undeclared_identifiers
(
self
):
return
self
.
expression_undeclared_identifiers
def
__repr__
(
self
):
return
"
%s(%s, %s, %s, %s)
"
%
(
self
.
__class__
.
__name__
,
repr
(
self
.
keyword
),
repr
(
self
.
attributes
),
repr
((
self
.
lineno
,
self
.
pos
)),
repr
([
repr
(
x
)
for
x
in
self
.
nodes
]))
...
...
@@ -219,8 +224,6 @@ class NamespaceTag(Tag):
self
.
name
=
attributes
[
'
name
'
]
def
declared_identifiers
(
self
):
return
[
self
.
name
]
def
undeclared_identifiers
(
self
):
return
[]
class
ComponentTag
(
Tag
):
__keyword__
=
'
component
'
...
...
This diff is collapsed.
Click to expand it.
test/inheritance.py
+
7
−
3
View file @
53a7f8bb
...
...
@@ -95,7 +95,6 @@ ${next.body()}
<%inherit file=
"
base
"
/>
this is index.
a is: ${self.a()}
<%include file=
"
secondary
"
/>
"""
)
...
...
@@ -105,6 +104,7 @@ ${next.body()}
a is: ${self.a()}
"""
)
print
collection
.
get_template
(
"
index
"
).
code
print
collection
.
get_template
(
"
index
"
).
render
()
def
test_namespaces
(
self
):
...
...
@@ -124,7 +124,7 @@ ${next.body()}
collection
.
put_string
(
"
layout
"
,
"""
<html>
<%inherit file=
"
base
"
/>
<%component name=
"
a
"
>layout_a</%component>
<%component name=
"
a
()
"
>layout_a</%component>
This is the layout..
${next.body()}
</html>
...
...
@@ -137,13 +137,17 @@ ${next.body()}
a is: ${self.a()}
sc.a is: ${sc.a()}
sc.b is: ${sc.b()}
sc.c is: ${sc.c()}
sc.body is: ${sc.body()}
"""
)
collection
.
put_string
(
"
secondary
"
,
"""
<%inherit file=
"
layout
"
/>
<%component name=
"
c
"
>secondary_c. a is ${self.a()} b is ${self.b()}</%component>
<%component name=
"
c
"
>secondary_c. a is ${self.a()} b is ${self.b()} d is ${self.d()}</%component>
<%component name=
"
d
"
>secondary_d.</%component>
this is secondary.
a is: ${self.a()}
c is: ${self.c()}
"""
)
print
collection
.
get_template
(
'
index
'
).
render
()
...
...
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