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
+++ b/contenttransformer/transformers.py
@@ -53,8 +53,26 @@ class RestructuredText(Transformer):
     settings = { 'report_level': 5 }
 
     def transform(self, request):
         """template: genshi(?) template to use (???)"""
         html = docutils.core.publish_string(self.content,
                                             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
+++ b/setup.py
@@ -26,11 +26,12 @@ setup(name='contenttransformer',
       entry_points="""
       # -*- Entry points: -*-
       [paste.app_factory]
       main = contenttransformer.factory:factory
 
       [content_transformers]
       Graphviz = contenttransformer.transformers:Graphviz
       ReST = contenttransformer.transformers:RestructuredText
+      Genshi = contenttransformer.transformers:GenshiTransformer
       """,
       )