Skip to content
Snippets Groups Projects
Commit 53a7f8bb authored by Mike Bayer's avatar Mike Bayer
Browse files

more inheritance tests and turning on attribute-embedded expressions

parent 706d9657
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
......@@ -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'
......
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment