Mercurial > genshi > mirror
changeset 650:9ff8eccc6f1f trunk
Code blocks in match templates are now executed. Closes #155. Many thanks to Andrew Sutherland for the patch!
author | cmlenz |
---|---|
date | Mon, 08 Oct 2007 08:04:58 +0000 |
parents | 717bbfe5bbdc |
children | badb73198fb1 |
files | ChangeLog genshi/template/markup.py genshi/template/tests/markup.py |
diffstat | 3 files changed, 19 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -33,6 +33,7 @@ set to "xml" (the default), the include is processed as before, but when set to "text", the included template is parsed as a text template using the new syntax (ticket #101). + * Python code blocks inside match templates are now executed (ticket #155). Version 0.4.4
--- a/genshi/template/markup.py +++ b/genshi/template/markup.py @@ -292,9 +292,9 @@ remaining = match_templates if 'match_once' not in hints: remaining = remaining[:idx] + remaining[idx + 1:] - for event in self._match(self._eval(self._flatten(template, - ctxt), - ctxt), ctxt, remaining): + for event in self._match(self._exec( + self._eval(self._flatten(template, ctxt), + ctxt), ctxt), ctxt, remaining): yield event ctxt.pop()
--- a/genshi/template/tests/markup.py +++ b/genshi/template/tests/markup.py @@ -596,6 +596,21 @@ </html>""") tmpl = MarkupTemplate(xml, filename='test.html', allow_exec=True) + def test_exec_in_match(self): + xml = ("""<html xmlns:py="http://genshi.edgewall.org/"> + <py:match path="body/p"> + <?python title="wakka wakka wakka" ?> + ${title} + </py:match> + <body><p>moot text</p></body> + </html>""") + tmpl = MarkupTemplate(xml, filename='test.html', allow_exec=True) + self.assertEqual("""<html> + <body> + wakka wakka wakka + </body> + </html>""", tmpl.generate().render()) + def suite(): suite = unittest.TestSuite()