Mercurial > genshi > mirror
comparison markup/filters.py @ 21:b4d17897d053 trunk
* Include paths are now interpreted relative to the path of the including template. Closes #3.
* The filename is now included as first item in the `pos` tuple of stream events.
* Simplified the "basic" example so that it actually ''is'' basic.
* Added a more complex example using nested relative includes in [source:/trunk/examples/includes/ examples/includes].
author | cmlenz |
---|---|
date | Tue, 20 Jun 2006 13:05:37 +0000 |
parents | 5420cfe42d36 |
children | b4f78c05e5c9 |
comparison
equal
deleted
inserted
replaced
20:cc92d74ce9e5 | 21:b4d17897d053 |
---|---|
51 | 51 |
52 if ns_prefixes is None: | 52 if ns_prefixes is None: |
53 ns_prefixes = [] | 53 ns_prefixes = [] |
54 in_fallback = False | 54 in_fallback = False |
55 include_href, fallback_stream = None, None | 55 include_href, fallback_stream = None, None |
56 indent = 0 | |
57 | 56 |
58 for kind, data, pos in stream: | 57 for kind, data, pos in stream: |
59 | 58 |
60 if kind is Stream.START and data[0] in self.NAMESPACE \ | 59 if kind is Stream.START and data[0] in self.NAMESPACE \ |
61 and not in_fallback: | 60 and not in_fallback: |
62 tag, attrib = data | 61 tag, attrib = data |
63 if tag.localname == 'include': | 62 if tag.localname == 'include': |
64 include_href = attrib.get('href') | 63 include_href = attrib.get('href') |
65 indent = pos[1] | |
66 elif tag.localname == 'fallback': | 64 elif tag.localname == 'fallback': |
67 in_fallback = True | 65 in_fallback = True |
68 fallback_stream = [] | 66 fallback_stream = [] |
69 | 67 |
70 elif kind is Stream.END and data in self.NAMESPACE: | 68 elif kind is Stream.END and data in self.NAMESPACE: |
71 if data.localname == 'include': | 69 if data.localname == 'include': |
72 try: | 70 try: |
73 if not include_href: | 71 if not include_href: |
74 raise TemplateError('Include misses required ' | 72 raise TemplateError('Include misses required ' |
75 'attribute "href"') | 73 'attribute "href"') |
76 template = self.loader.load(include_href) | 74 template = self.loader.load(include_href, |
75 relative_to=pos[0]) | |
77 for event in template.generate(ctxt): | 76 for event in template.generate(ctxt): |
78 yield event | 77 yield event |
79 | 78 |
80 except TemplateNotFound: | 79 except TemplateNotFound: |
81 if fallback_stream is None: | 80 if fallback_stream is None: |
83 for event in fallback_stream: | 82 for event in fallback_stream: |
84 yield event | 83 yield event |
85 | 84 |
86 include_href = None | 85 include_href = None |
87 fallback_stream = None | 86 fallback_stream = None |
88 indent = 0 | |
89 | 87 |
90 elif data.localname == 'fallback': | 88 elif data.localname == 'fallback': |
91 in_fallback = False | 89 in_fallback = False |
92 | 90 |
93 elif in_fallback: | 91 elif in_fallback: |