changeset 12:59496de89997

allow graphviz to serve svg
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 30 Jun 2010 22:01:50 -0700
parents ba52425d1250
children 9d51954e2e68
files contenttransformer/transformers.py
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/contenttransformer/transformers.py
+++ b/contenttransformer/transformers.py
@@ -27,23 +27,32 @@ class ContentTypeChanger(Transformer):
     def __init__(self, content, from_type, to_type):
         self.to_type = to_type
         Transformer.__init__(self, content, from_type)
 
     def transform(self, request):
         return (self.to_type, self.content)
 
 class Graphviz(Transformer):
+    content_types = { 'png': 'image/png',
+                      'svg': 'image/svg+xml' }
+    
+    def __init__(self, content, content_type, format='png'):
+        self.format=format
+        Transformer.__init__(self, content, content_type)
+    
     def transform(self, request):
         """create a Graphviz object"""
-        process = subprocess.Popen(['dot', '-Tpng'],
+        _format = request.GET.get('format', self.format)
+        assert _format in self.content_types, 'Unknown format: ' + _format
+        process = subprocess.Popen(['dot', '-T' + _format],
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE)
         image, _ = process.communicate(self.content)
-        return ('image/png', image)
+        return (self.content_types[_format], image)
 
 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',