[Zope3-checkins] CVS: zopeproducts/zwiki/renderer - configure.zcml:1.3 plaintext.py:1.2 rest.py:1.3 stx.py:1.3

Stephan Richter srichter@cbu.edu
Sat, 12 Apr 2003 19:06:05 -0400


Update of /cvs-repository/zopeproducts/zwiki/renderer
In directory cvs.zope.org:/tmp/cvs-serv13171/renderer

Modified Files:
	configure.zcml plaintext.py rest.py stx.py 
Log Message:
- Finished a bunch of promised tests. Except for Views everything is tested
  now.

- Reworked the source type registry a bit to be more flexible. Now the
  actual implementation of a source type interface is also registered. I
  moved the createComment() method into the source class, since this is 
  where it belongs. We only want one createComment() method for each source
  and not for each renderer.


=== zopeproducts/zwiki/renderer/configure.zcml 1.2 => 1.3 ===
--- zopeproducts/zwiki/renderer/configure.zcml:1.2	Wed Apr  9 11:16:40 2003
+++ zopeproducts/zwiki/renderer/configure.zcml	Sat Apr 12 19:05:34 2003
@@ -4,7 +4,8 @@
 
 <wiki:sourcetype
     title="Plain Text" 
-    interface="zopeproducts.zwiki.interfaces.IPlainTextSource">
+    interface="zopeproducts.zwiki.interfaces.IPlainTextSource"
+    class=".plaintext.PlainTextSource">
   <wiki:renderer 
       for="zope.publisher.interfaces.browser.IBrowserPresentation" 
       factory=".plaintext.PlainTextToHTMLRenderer" />
@@ -12,7 +13,8 @@
 
 <wiki:sourcetype 
     title="Structured Text (STX)"
-    interface="zopeproducts.zwiki.interfaces.IStructuredTextSource">
+    interface="zopeproducts.zwiki.interfaces.IStructuredTextSource"
+    class=".stx.StructuredTextSource">
   <wiki:renderer 
       for="zope.publisher.interfaces.browser.IBrowserPresentation" 
       factory=".stx.StructuredTextToHTMLRenderer" />
@@ -20,7 +22,8 @@
 
 <wiki:sourcetype 
     title="reStructured Text (reST)" 
-    interface="zopeproducts.zwiki.interfaces.IReStructuredTextSource">
+    interface="zopeproducts.zwiki.interfaces.IReStructuredTextSource"
+    class=".rest.ReStructuredTextSource">
   <wiki:renderer 
       for="zope.publisher.interfaces.browser.IBrowserPresentation" 
       factory=".rest.ReStructuredTextToHTMLRenderer" />


=== zopeproducts/zwiki/renderer/plaintext.py 1.1 => 1.2 ===
--- zopeproducts/zwiki/renderer/plaintext.py:1.1	Tue Apr  8 22:49:11 2003
+++ zopeproducts/zwiki/renderer/plaintext.py	Sat Apr 12 19:05:34 2003
@@ -15,29 +15,32 @@
 
 $Id$
 """
-from datetime import datetime
-from zopeproducts.zwiki.interfaces import IPlainTextSource
+from zopeproducts.zwiki.interfaces import IPlainTextSource, IHTMLRenderer
 from zope.publisher.browser import BrowserView
 
+
+class PlainTextSource(unicode):
+    __implements__ = IPlainTextSource
+
+    def createComment(self, comment, number, user, date):
+        "See zopeproducts.zwiki.interfaces.IPlainTextSource"
+        if number == 1:
+            return first_comment_template %(number, user, date, comment)
+        else:
+            return comment_template %(number, user, date, comment)    
+    
+
 class PlainTextToHTMLRenderer(BrowserView):
-    __implements__ = BrowserView.__implements__
+    __implements__ = BrowserView.__implements__, IHTMLRenderer
     __used_for__ = IPlainTextSource
 
     def render(self, context):
+        "See zopeproducts.zwiki.interfaces.IHTMLRenderer"
         html = self.context.replace('\n', '<br/>\n')
-        html = html.replace('----------',
+        html = html.replace('----------<br/>',
                             '<hr class="comments" size="1" NOSHADE>')
         return html
 
-    def createComment(self, comment, number):
-        date = self.request.locale.getDateTimeFormatter('medium').format(
-            datetime.now())
-        user = self.request.user.getLogin()
-        if number == 1:
-            return first_comment_template %(number, user, date, comment)
-        else:
-            return comment_template %(number, user, date, comment)
-    
 
 comment_template = '''
 


=== zopeproducts/zwiki/renderer/rest.py 1.2 => 1.3 ===
--- zopeproducts/zwiki/renderer/rest.py:1.2	Thu Apr 10 12:07:36 2003
+++ zopeproducts/zwiki/renderer/rest.py	Sat Apr 12 19:05:34 2003
@@ -23,14 +23,28 @@
 
 from datetime import datetime
 from zope.publisher.browser import BrowserView
-from zopeproducts.zwiki.interfaces import IStructuredTextSource
+from zopeproducts.zwiki.interfaces import \
+     IReStructuredTextSource, IHTMLRenderer
 from StructuredText import HTML
 
+
+class ReStructuredTextSource(unicode):
+    __implements__ = IReStructuredTextSource
+
+    def createComment(self, comment, number, user, date):
+        "See zopeproducts.zwiki.interfaces.IReStructuredTextSource"
+        if number == 1:
+            return first_comment_template %(number, user, date, comment)
+        else:
+            return comment_template %(number, user, date, comment)
+
+
 class ReStructuredTextToHTMLRenderer(BrowserView):
-    __implements__ = BrowserView.__implements__
-    __used_for__ = IStructuredTextSource
+    __implements__ = BrowserView.__implements__, IHTMLRenderer
+    __used_for__ = IReStructuredTextSource
 
     def render(self, context):
+        "See zopeproducts.zwiki.interfaces.IHTMLRenderer"
         if docutils == None:
             return "<h2>You do not have Python docutils installed.</h2>"
         # format with strings
@@ -68,18 +82,9 @@
         # do the format
         html = pub.writer.write(document, pub.destination)
         html = re.sub(
-            r'(?sm)^<html.*<body.*?>\n(.*)</body>\n</html>\n',r'\1', html)
+            r'(?sm)^<\?xml.*<html.*<body.*?>\n(.*)</body>\n</html>\n',r'\1',
+            html)
         return html
-        
-
-    def createComment(self, comment, number):
-        date = self.request.locale.getDateTimeFormatter('medium').format(
-            datetime.now())
-        user = self.request.user.getLogin()
-        if number == 1:
-            return first_comment_template %(number, user, date, comment)
-        else:
-            return comment_template %(number, user, date, comment)
     
 
 comment_template = '''


=== zopeproducts/zwiki/renderer/stx.py 1.2 => 1.3 ===
--- zopeproducts/zwiki/renderer/stx.py:1.2	Thu Apr 10 02:28:16 2003
+++ zopeproducts/zwiki/renderer/stx.py	Sat Apr 12 19:05:34 2003
@@ -16,37 +16,42 @@
 $Id$
 """
 import re
+
 from datetime import datetime
 from zope.publisher.browser import BrowserView
-from zopeproducts.zwiki.interfaces import IStructuredTextSource
+from zopeproducts.zwiki.interfaces import IStructuredTextSource, IHTMLRenderer
+
 from StructuredText import HTML
 
+
+class StructuredTextSource(unicode):
+    __implements__ = IStructuredTextSource
+
+    def createComment(self, comment, number, user, date):
+        "See zopeproducts.zwiki.interfaces.IStructuredTextSource"
+        if number == 1:
+            return first_comment_template %(number, user, date, comment)
+        else:
+            return comment_template %(number, user, date, comment)    
+    
+
 class StructuredTextToHTMLRenderer(BrowserView):
-    __implements__ = BrowserView.__implements__
+    __implements__ = BrowserView.__implements__, IHTMLRenderer
     __used_for__ = IStructuredTextSource
 
     def render(self, context):
+        "See zopeproducts.zwiki.interfaces.IHTMLRenderer"
         html = HTML(str(self.context))
 
         # strip html & body added by some zope versions
         html = re.sub(
             r'(?sm)^<html.*<body.*?>\n(.*)</body>\n</html>\n',r'\1', html)
 
-        html = html.replace('\n----------',
-                            '\n<hr class="comments" size="1" NOSHADE>\n')
+        html = html.replace('<p>----------</p>',
+                            '<hr class="comments" size="1" NOSHADE>')
         return html
 
 
-    def createComment(self, comment, number):
-        date = self.request.locale.getDateTimeFormatter('medium').format(
-            datetime.now())
-        user = self.request.user.getLogin()
-        if number == 1:
-            return first_comment_template %(number, user, date, comment)
-        else:
-            return comment_template %(number, user, date, comment)
-    
-
 comment_template = '''
 
 Comment #%i by **%s** (%s)
@@ -54,6 +59,7 @@
 %s'''
 
 first_comment_template = '''
+
 ----------
 
 Comment #%i by **%s** (%s)