[z3-checkins] r28619 - z3/Sfive/trunk

philikon at codespeak.net philikon at codespeak.net
Sat Jun 10 16:31:47 CEST 2006


Author: philikon
Date: Sat Jun 10 16:31:40 2006
New Revision: 28619

Modified:
   z3/Sfive/trunk/browser.py
Log:
Use docutils 0.4.0's ability to render s5 compatible markup instead
of trying to do all sorts of weird monkey business...


Modified: z3/Sfive/trunk/browser.py
==============================================================================
--- z3/Sfive/trunk/browser.py	(original)
+++ z3/Sfive/trunk/browser.py	Sat Jun 10 16:31:40 2006
@@ -1,46 +1,26 @@
 import os
-from StringIO import StringIO
-from datetime import date
-from zope.app import zapi
-from zope.app.renderer.interfaces import IHTMLRenderer
-from Products.Five import BrowserView
-
-class PresentationView(BrowserView):
-
-    def render(self):
-        source = zapi.createObject(None, self.context.type,
-                                   self.context.text)
-        renderer = zapi.getMultiAdapter((source, self.request), IHTMLRenderer)
-        #return renderer.render()
-        #XXX work around a bug in docutils or so
-        return renderer.render().decode('utf-8')
-
-    def renderAndAdjust(self):
-        body = self.render()
-        body = body.strip()
-        body = body[23:-7]
-        #body.replace('<div class="document">', '')
-        body = body.replace('<div class="section"', '<div class="slide"')
-        body = body.replace('<h3>', '<h1>')
-        body = body.replace('</h3>', '</h1>')
-        return body
-
-    def renderAndAdjustLXML(self):
-        from lxml import etree
-        body = self.render()
-
-        xsltfile = os.path.join(os.path.dirname(__file__), 'transform.xsl')
-        xslt = file(xsltfile)
-        xslt_doc = etree.parse(xslt)
-        style = etree.XSLT(xslt_doc)
-
-        body = body.strip() #XXX work around a bug in lxml
-        bodyfile = StringIO(body)
-        doc = etree.parse(bodyfile)
-        result = style.apply(doc)
-        return style.tostring(result)
+import datetime
+import docutils.core
+from docutils.writers import s5_html
+from zope.traversing.browser import absoluteURL
+from zope.publisher.browser import BrowserPage
+
+class ViewPresentation(BrowserPage):
+
+    def __call__(self):
+        return docutils.core.publish_string(
+            self.context.text,
+            writer = s5_html.Writer(),
+            settings_overrides = {
+                'input_encoding': 'unicode',
+                'output_encoding': 'unicode',
+                'theme': None,
+                'theme_url': (absoluteURL(self.context, self.request) +
+                              '/++resource++s5ui')
+                }
+            )
 
     def todaysDate(self):
-        today = date.today()
+        today = datetime.date.today()
         #XXX should use locale formatter here
         return today.strftime("%d %b %Y")


More information about the z3-checkins mailing list