def genshihtmltemplate(s): # Add namespace py: in s = '<div xmlns:py="http://genshi.edgewall.org/" py:strip="True">%s</div>' % s template = GenshiTemplate(s) def rendergenshihtml(obj): tvars = {'here':obj, 'container':obj.parentNode, 'markup':markup, 'config':obj.ownerDocument.config, 'template':template, 'context':obj.ownerDocument.context, 'templates':obj.renderer} return str(template.generate(**tvars).render(method='html')) return rendergenshihtml
except ImportError: test_genshi = None else: genshi_template = GenshiTemplate("""\ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/"> <head> <title>${page_title}</title> </head> <body> <div class="header"> <h1>${page_title}</h1> </div> <ul class="navigation"> <li py:for="href, caption in [ ('index.html', 'Index'), ('downloads.html', 'Downloads'), ('products.html', 'Products')]"><a href="${href}">${caption}</a></li> </ul> <div class="table"> <table> <tr py:for="row in table"> <td py:for="cell in row">${cell}</td> </tr> </table> </div> </body> </html>\ """) def test_genshi(): genshi_template.generate(**context).render('html', strip_whitespace=False)