changeset 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
files markup/filters.py markup/template.py
diffstat 2 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/markup/filters.py
+++ b/markup/filters.py
@@ -87,13 +87,16 @@
 
     _NAMESPACE = 'http://www.w3.org/2001/XInclude'
 
-    def __init__(self, loader):
+    def __init__(self, loader, template):
         """Initialize the filter.
         
         @param loader: the `TemplateLoader` to use for resolving references to
             external template files
         """
         self.loader = loader
+        self.template = template
+        if not hasattr(template, '_included_filters'):
+            template._included_filters = []
 
     def __call__(self, stream, ctxt=None, ns_prefixes=None):
         """Filter the stream, processing any XInclude directives it may
@@ -138,9 +141,13 @@
                         # If the included template defines any filters added at
                         # runtime (such as py:match templates), those need to be
                         # applied to the including template, too.
-                        for filter_ in template.filters:
+                        filters = template.filters + template._included_filters
+                        for filter_ in filters:
                             stream = filter_(stream, ctxt)
 
+                        # Runtime filters included need to be propagated up
+                        self.template._included_filters += filters
+
                     except TemplateNotFound:
                         if fallback_stream is None:
                             raise
--- a/markup/template.py
+++ b/markup/template.py
@@ -770,7 +770,7 @@
                 fileobj = file(filepath, 'rt')
                 try:
                     tmpl = Template(fileobj, filename=filepath)
-                    tmpl.pre_filters.append(IncludeFilter(self))
+                    tmpl.pre_filters.append(IncludeFilter(self, tmpl))
                 finally:
                     fileobj.close()
                 self._cache[filename] = tmpl
Copyright (C) 2012-2017 Edgewall Software