Mercurial > genshi > genshi-test
comparison markup/filters.py @ 13:bf9de5a4c896
Match directives should now also be applied when included indirectly.
For example, a match directive defined in `a.html`, which is included by `b.html`, which in turn is included by `c.html` should now also be applied to `c.html`.
author | cmlenz |
---|---|
date | Mon, 05 Jun 2006 00:03:43 +0000 |
parents | 87238328a71d |
children | 76b5d4b189e6 |
comparison
equal
deleted
inserted
replaced
12:87238328a71d | 13:bf9de5a4c896 |
---|---|
85 (see http://www.w3.org/TR/xinclude/) in templates. | 85 (see http://www.w3.org/TR/xinclude/) in templates. |
86 """ | 86 """ |
87 | 87 |
88 _NAMESPACE = 'http://www.w3.org/2001/XInclude' | 88 _NAMESPACE = 'http://www.w3.org/2001/XInclude' |
89 | 89 |
90 def __init__(self, loader): | 90 def __init__(self, loader, template): |
91 """Initialize the filter. | 91 """Initialize the filter. |
92 | 92 |
93 @param loader: the `TemplateLoader` to use for resolving references to | 93 @param loader: the `TemplateLoader` to use for resolving references to |
94 external template files | 94 external template files |
95 """ | 95 """ |
96 self.loader = loader | 96 self.loader = loader |
97 self.template = template | |
98 if not hasattr(template, '_included_filters'): | |
99 template._included_filters = [] | |
97 | 100 |
98 def __call__(self, stream, ctxt=None, ns_prefixes=None): | 101 def __call__(self, stream, ctxt=None, ns_prefixes=None): |
99 """Filter the stream, processing any XInclude directives it may | 102 """Filter the stream, processing any XInclude directives it may |
100 contain. | 103 contain. |
101 | 104 |
136 yield ikind, idata, ipos | 139 yield ikind, idata, ipos |
137 | 140 |
138 # If the included template defines any filters added at | 141 # If the included template defines any filters added at |
139 # runtime (such as py:match templates), those need to be | 142 # runtime (such as py:match templates), those need to be |
140 # applied to the including template, too. | 143 # applied to the including template, too. |
141 for filter_ in template.filters: | 144 filters = template.filters + template._included_filters |
145 for filter_ in filters: | |
142 stream = filter_(stream, ctxt) | 146 stream = filter_(stream, ctxt) |
147 | |
148 # Runtime filters included need to be propagated up | |
149 self.template._included_filters += filters | |
143 | 150 |
144 except TemplateNotFound: | 151 except TemplateNotFound: |
145 if fallback_stream is None: | 152 if fallback_stream is None: |
146 raise | 153 raise |
147 for event in fallback_stream: | 154 for event in fallback_stream: |