Mercurial > genshi > genshi-test
changeset 364:41d6eb7885ec
Fix for #77: match templates were matching their own output.
author | cmlenz |
---|---|
date | Wed, 22 Nov 2006 16:52:34 +0000 |
parents | caf7b68ab5dc |
children | 85d910b8f9e5 |
files | genshi/path.py genshi/template/markup.py genshi/template/tests/directives.py |
diffstat | 3 files changed, 53 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/genshi/path.py +++ b/genshi/path.py @@ -550,7 +550,7 @@ return '%s:*' % self.prefix class LocalNameTest(object): - """Node test that matches any event with the given prinipal type and + """Node test that matches any event with the given principal type and local name. """ __slots__ = ['principal_type', 'name'] @@ -567,7 +567,7 @@ return self.name class QualifiedNameTest(object): - """Node test that matches any event with the given prinipal type and + """Node test that matches any event with the given principal type and qualified name. """ __slots__ = ['principal_type', 'prefix', 'name']
--- a/genshi/template/markup.py +++ b/genshi/template/markup.py @@ -249,7 +249,9 @@ # Consume and store all events until an end event # corresponding to this start event is encountered - content = chain([event], self._match(_strip(stream), ctxt), + content = chain([event], + self._match(_strip(stream), ctxt, + [match_templates[idx]]), tail) content = list(self._include(content, ctxt))
--- a/genshi/template/tests/directives.py +++ b/genshi/template/tests/directives.py @@ -599,6 +599,54 @@ </body> </html>""", str(tmpl.generate())) + def test_not_match_self(self): + """ + See http://genshi.edgewall.org/ticket/77 + """ + tmpl = MarkupTemplate("""<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:py="http://genshi.edgewall.org/"> + <body py:match="body" py:content="select('*')" /> + <h1 py:match="h1"> + ${select('text()')} + Goodbye! + </h1> + <body> + <h1>Hello!</h1> + </body> + </html>""") + self.assertEqual("""<html xmlns="http://www.w3.org/1999/xhtml"> + <body><h1> + Hello! + Goodbye! + </h1></body> + </html>""", str(tmpl.generate())) + + def test_select_text_in_element(self): + """ + See http://genshi.edgewall.org/ticket/77#comment:1 + """ + tmpl = MarkupTemplate("""<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:py="http://genshi.edgewall.org/"> + <body py:match="body" py:content="select('*')" /> + <h1 py:match="h1"> + <text> + ${select('text()')} + </text> + Goodbye! + </h1> + <body> + <h1>Hello!</h1> + </body> + </html>""") + self.assertEqual("""<html xmlns="http://www.w3.org/1999/xhtml"> + <body><h1> + <text> + Hello! + </text> + Goodbye! + </h1></body> + </html>""", str(tmpl.generate())) + def test_select_all_attrs(self): tmpl = MarkupTemplate("""<doc xmlns:py="http://genshi.edgewall.org/"> <div py:match="elem" py:attrs="select('@*')">