Skip to content

Commit

Permalink
Merge pull request #240 from NextThought/issue238
Browse files Browse the repository at this point in the history
Assign to macroname at the point of use, not definition.
  • Loading branch information
malthe committed May 8, 2017
2 parents a6df9f3 + 44cbc58 commit fed4ea5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/chameleon/tests/outputs/238.pt
Expand Up @@ -3,5 +3,5 @@



<h1>page</h1>
<h1>macros['page']</h1>

16 changes: 12 additions & 4 deletions src/chameleon/zpt/program.py
Expand Up @@ -233,10 +233,21 @@ def visit_element(self, start, end, children):
inner = nodes.UseExternalMacro(
nodes.Value(use_macro), slots, False
)
macro_name = use_macro
else:
inner = nodes.UseExternalMacro(
nodes.Value(extend_macro), slots, True
)
macro_name = extend_macro

# While the macro executes, it should have access to the name it was
# called with as 'macroname'. Splitting on / mirrors zope.tal and is a
# concession to the path expression syntax.
macro_name = macro_name.rsplit('/', 1)[-1]
inner = nodes.Define(
[nodes.Assignment(["macroname"], Static(ast.Str(macro_name)), True)],
inner,
)
# -or- include tag
else:
content = nodes.Sequence(body)
Expand Down Expand Up @@ -555,10 +566,7 @@ def visit_element(self, start, end, children):
clause
)

self._macros[clause] = nodes.Define(
[nodes.Assignment(["macroname"], Static(ast.Str(clause)), True)],
slot,
)
self._macros[clause] = slot
slot = nodes.UseInternalMacro(clause)

slot = wrap(
Expand Down

0 comments on commit fed4ea5

Please sign in to comment.