diff --git a/lib/mako/codegen.py b/lib/mako/codegen.py index ff801a58c05a33d363d292a8fe714126bfc56fa5..fb54df176515141d830415a94dcd59600e90eb1a 100644 --- a/lib/mako/codegen.py +++ b/lib/mako/codegen.py @@ -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: diff --git a/lib/mako/parsetree.py b/lib/mako/parsetree.py index 5f49ae768839aa41d3b4c39d2fe688290adac404..fece1af98a15492ede16adbb2b720a5be3bb45f0 100644 --- a/lib/mako/parsetree.py +++ b/lib/mako/parsetree.py @@ -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' diff --git a/test/inheritance.py b/test/inheritance.py index ccd9b155a34bb7a66afa05341ecbf9ef6c9280ce..0df7ef0ad48f26e0f526eaf544b5030129086b64 100644 --- a/test/inheritance.py +++ b/test/inheritance.py @@ -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()