changeset 18:7800c6553c77

merge commit
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 26 Sep 2010 19:58:46 -0700
parents 0ad456dbb4c5 (current diff) 6cbe4172b54b (diff)
children afd11b758da0
files
diffstat 2 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/contenttransformer/transformers.py
+++ b/contenttransformer/transformers.py
@@ -1,10 +1,11 @@
 import docutils.core
 import subprocess
+from utils import import_path
 from webob import Request, Response
 
 class Transformer(object):
     """abstract base class for transformer objects"""
     def __init__(self, content, content_type):
         self.content = content
         self.content_type = content_type
 
@@ -60,17 +61,25 @@ class RestructuredText(Transformer):
         return ('text/html', html)
 
 try:
     import genshi
     from genshi.template import MarkupTemplate
 
     class GenshiTransformer(Transformer):
 
-        def __init__(self, content, content_type):
+        def __init__(self, content, content_type, modules=()):
+            """
+            - modules : strings of modules
+            """
+            self.variables = {}
+            for path in modules:
+                module = import_path(path)
+                name = path.rsplit('.')[-1]
+                self.variables[name] = module
             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'))
 
new file mode 100644
--- /dev/null
+++ b/contenttransformer/utils.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+
+def import_path(module):
+  path = module.split('.')
+  module = __import__(path[0])
+  for name in path[1:]:
+    module = getattr(module, name)
+  return module
+
+if __name__ == '__main__':
+  import sys
+  for i in sys.argv[1:]:
+    print import_path(i)