Opened 16 years ago
Last modified 8 years ago
#268 new defect
Match templates cannot access function variables
Reported by: | nabil.stendardo@… | Owned by: | cmlenz |
---|---|---|---|
Priority: | major | Milestone: | 0.9 |
Component: | General | Version: | 0.5.1 |
Keywords: | Cc: |
Description
It seems as though match templates cannot access variables of a function in which they are nested. Example
<?xml version="1.0" encoding="UTF-8"?> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/"> <head></head> <py:def function="test(x)"> <py:match path="test_tag"> <p>There should be another line of text if works</p> <p>${x}</p> </py:match> </py:def> ${test('This example works as expected')} <body> <test_tag /> </body> </html>
does not compile, and if we replace ${x} by ${value_of('x')}, it doesn't print the second line.
Change History (5)
comment:1 Changed 15 years ago by cmlenz
- Milestone changed from 0.6 to 0.6.1
comment:2 follow-up: ↓ 3 Changed 15 years ago by Carsten Klein <carsten.klein@…>
comment:3 in reply to: ↑ 2 ; follow-up: ↓ 4 Changed 14 years ago by Carsten Klein <carsten.klein@…>
Replying to Carsten Klein <carsten.klein@…>:
Just had a closer look on the extract_directives function and DefDirective#call?, and from what I have learnt from there, the above is nonsense. Must have been late.
comment:4 in reply to: ↑ 3 Changed 14 years ago by Carsten Klein <carsten.klein@…>
Replying to Carsten Klein <carsten.klein@…>:
Replying to Carsten Klein <carsten.klein@…>:
Just had a closer look on the extract_directives function and DefDirective#call?, and from what I have learnt from there, the above is nonsense. Must have been late.
And nonsense again *sigh*
Looking closer at the inner workings of the match function, it shows that when applying directives, _flatten will no longer be called, which is actually responsible for evaluating the expressions in the stream.
So basically, whenever the def directive is being called, it will recursively apply all directives to the stream that is being matched, but then it will just return the resulting stream, without that any of the expressions have been evaluated by _flatten.
comment:5 Changed 8 years ago by hodgestar
- Milestone changed from 0.6.1 to 0.9
Move to milestone 0.9.
Basically, I think this is based on the fact that _apply_directives is being run prior to that the _match function will recursively process the resulting output stream, leaving the context untouched. So whenever the DefDirective? sets up a new scope, that scope will be removed as soon as recursive processing of the directives took place.
See the _match funtion in the Markup or Text template classes.
Here is a link to the line that actually causes this behaviour trunk/genshi/template/markup.py#L374.
What would basically be required is inline application of the directives as they occur, so that the current context's scope that was set up by any directive will be inherited by any of the stream events within that context.
I wonder if it would be possible to instead of extracting all directives from the stream first, apply each directive as it is being encountered during iteration in the inner for loop.