changeset 15:946176949bba

add the genshi transformer
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 06 Sep 2010 08:45:30 -0700
parents 7dae51af8db6
children 6cbe4172b54b 0ad456dbb4c5
files contenttransformer/transformers.py setup.py
diffstat 2 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/contenttransformer/transformers.py	Wed Jun 30 22:32:33 2010 -0700
+++ b/contenttransformer/transformers.py	Mon Sep 06 08:45:30 2010 -0700
@@ -58,3 +58,21 @@
                                             writer_name='html',
                                             settings_overrides=self.settings)
         return ('text/html', html)
+
+try:
+    import genshi
+    from genshi.template import MarkupTemplate
+
+    class GenshiTransformer(Transformer):
+
+        def __init__(self, content, content_type):
+            Transformer.__init__(self, content, content_type)
+        
+        def transform(self, request):
+            variables = dict(request=request)
+            template = MarkupTemplate(self.content)
+            stream = template.generate(**variables)
+            return ('text/html', stream.render('html', doctype='html'))
+
+except ImportError:
+    pass
--- a/setup.py	Wed Jun 30 22:32:33 2010 -0700
+++ b/setup.py	Mon Sep 06 08:45:30 2010 -0700
@@ -31,6 +31,7 @@
       [content_transformers]
       Graphviz = contenttransformer.transformers:Graphviz
       ReST = contenttransformer.transformers:RestructuredText
+      Genshi = contenttransformer.transformers:GenshiTransformer
       """,
       )