[Zope3-checkins] CVS: zopeproducts/zwiki - READMDE.txt:1.3 TODO.txt:1.3 browser.py:1.5 configure.zcml:1.7 interfaces.py:1.3 zwiki.py:1.8

Stephan Richter srichter@cbu.edu
Tue, 8 Apr 2003 00:15:36 -0400


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

Modified Files:
	READMDE.txt TODO.txt browser.py configure.zcml interfaces.py 
	zwiki.py 
Log Message:
The left overs of all of the previous changes. 


=== zopeproducts/zwiki/READMDE.txt 1.2 => 1.3 ===
--- zopeproducts/zwiki/READMDE.txt:1.2	Mon Apr  7 03:15:31 2003
+++ zopeproducts/zwiki/READMDE.txt	Tue Apr  8 00:15:02 2003
@@ -21,3 +21,8 @@
     - Assinging parents, allowing to create a "virtual" hierarchy.
 
     - Writing comments about the Wiki Page.
+
+    - Somewhat sophistocated rendering mechanism. New source types and their
+      render methods can now be configured (added) via ZCML.
+
+    - Implemented minimal STX support.
\ No newline at end of file


=== zopeproducts/zwiki/TODO.txt 1.2 => 1.3 ===
--- zopeproducts/zwiki/TODO.txt:1.2	Mon Apr  7 03:15:31 2003
+++ zopeproducts/zwiki/TODO.txt	Tue Apr  8 00:15:02 2003
@@ -7,17 +7,14 @@
 
     - Add test for findChildren.
 
-    - Write tests for comment() method in WikiPage.
+    - Add tests for metaconfigure.py
 
+    - Add tests for plain text and STX formatter.
+    
 
   Rendering/Views
 
-    - Implement RenderingEngineService that maintains a registry of all
-      available rendering methods, so that we can easily plug in new
-      engines. Note that the original Zwiki product hard-codes all of the
-      rendering possibilities, making ZWikiPage a huge class.
-
-    - Incorporate STX and ReST in the Zope 3 core or at least in this product.
+    - Incorporate ReST in the Zope 3 core or at least in this product.
 
     - Create a custom skin, so that we are not relying on the standard Zope 3
       skin.
@@ -32,6 +29,8 @@
     - Table of Contents including unlinked and unparented WikiPages.
 
     - Improve 'Add Comment' screen to show existing Wiki content.
+
+    - Custom Widget for source types is not working. Needs to be fixed.
 
 
   Other Features


=== zopeproducts/zwiki/browser.py 1.4 => 1.5 ===
--- zopeproducts/zwiki/browser.py:1.4	Mon Apr  7 03:15:31 2003
+++ zopeproducts/zwiki/browser.py	Tue Apr  8 00:15:02 2003
@@ -20,13 +20,14 @@
 
 from zope.app.interfaces.dublincore import ICMFDublinCore
 
-from zope.component import getAdapter
+from zope.component import getAdapter, getView, getService
 from zope.app.browser.container.adding import Adding
+from zope.app.browser.form.widget import ListWidget
+from zope.app.form.widget import CustomWidget
 from zope.app.traversing import getParent, getPath, objectName
 
 from zopeproducts.zwiki.interfaces import IWikiPageHierarchy
 
-
 urlchars = r'[A-Za-z0-9/:@_%~#=&\.\-\?\+\$,]+'
 urlendchar  = r'[A-Za-z0-9/]'
 url = r'["=]?((about|gopher|http|https|ftp|mailto|file):%s)' %urlchars
@@ -51,6 +52,46 @@
     menu_id = "add_wiki"
 
 
+class SourceTypeWidget(ListWidget):
+
+    size = 1
+
+    def renderItems(self, value):
+        name = self.name
+        # get items
+        types = getService(self.context, "WikiSourceTypeRegistry")
+        items = types.getAllTitles()
+
+        # check if we want to select first item
+        if (not value and getattr(self.context, 'firstItem', False)
+            and len(items) > 0):
+            value = items[0]
+
+        cssClass = self.getValue('cssClass')
+
+        rendered_items = []
+        count = 0
+        for item_value in items:
+            item_text = self.textForValue(item_value)
+
+            if item_value == value:
+                rendered_item = self.renderSelectedItem(
+                    count, item_text, item_value, name, cssClass)
+            else:
+                rendered_item = self.renderItem(
+                    count, item_text, item_value, name, cssClass)
+
+            rendered_items.append(rendered_item)
+            count += 1
+
+        return rendered_items
+    
+
+class EditWikiPage(object):
+
+    type = CustomWidget(SourceTypeWidget)
+
+
 class ViewWikiPage:
     """A rendered View of the wiki page."""
 
@@ -90,8 +131,12 @@
 
     def render(self):
         """Render the wiki page source."""
-        html = self.renderWikiLinks(self.context.source)
-        html = html.replace('\n', '<br/>\n')
+        types = getService(self.context, "WikiSourceTypeRegistry")
+        source = types.createObject(self.context.type,
+                                    self.context.source)
+        view = getView(source, None, self.request)
+        html = view.render(self.context, self.request)
+        html = self.renderWikiLinks(html)
         return html
 
     def _protectLine(self, match):


=== zopeproducts/zwiki/configure.zcml 1.6 => 1.7 ===
--- zopeproducts/zwiki/configure.zcml:1.6	Mon Apr  7 03:15:31 2003
+++ zopeproducts/zwiki/configure.zcml	Tue Apr  8 00:15:02 2003
@@ -1,6 +1,7 @@
 <zopeConfigure
    xmlns="http://namespaces.zope.org/zope"
-   xmlns:browser="http://namespaces.zope.org/browser">
+   xmlns:browser="http://namespaces.zope.org/browser"
+   xmlns:wiki="http://namespaces.zope.org/wiki">
 
   <content class=".zwiki.Wiki">
 
@@ -95,24 +96,25 @@
       />
 
   <browser:addform
+      label="Add Wiki Page"
       name="AddWikiPage"
       schema=".interfaces.IWikiPage"
-      label="Add Wiki Page"
       content_factory=".zwiki.WikiPage"
       permission="zope.ManageContent"
       fields="source type"
+      class=".browser.EditWikiPage."
       menu="add_wiki"
       title="Wiki Page"/>
 
   <browser:editform
       schema=".interfaces.IWikiPage"
+      for=".interfaces.IWikiPage"
       label="Change Wiki Page"
       name="edit.html"
-      for=".interfaces.IWikiPage"
       permission="zope.ManageContent"
-      menu="zmi_views"
-      title="Edit"
-      fields="source type"/>
+      fields="source type"
+      class=".browser.EditWikiPage."
+      menu="zmi_views" title="Edit" />
 
   <browser:page
       name="view.html"
@@ -123,7 +125,6 @@
       menu="zmi_views"
       title="View"/>
 
-
   <browser:pages
       for=".interfaces.IWikiPage"
       class=".browser.EditWikiParents"
@@ -151,5 +152,35 @@
       for=".interfaces.IWikiPage"
       file="wikipage_icon.gif"
       />
+
+<!-- Wiki-specifc configuration -->
+
+<serviceType 
+    id="WikiSourceTypeRegistry"
+    interface=".interfaces.IWikiSourceTypeService" />
+
+<service 
+    serviceType="WikiSourceTypeRegistry"
+    permission="zope.View"
+    component=".sourcetype.SourceTypes" />
+
+<include file="meta.zcml" />
+
+<wiki:sourcetype
+    title="Plain Text" 
+    interface=".interfaces.IPlainTextSource">
+  <wiki:renderer 
+      for="zope.publisher.interfaces.browser.IBrowserPresentation" 
+      factory=".plaintext.PlainTextToHTMLRenderer" />
+</wiki:sourcetype>
+
+<wiki:sourcetype 
+    title="Structured Text" 
+    interface=".interfaces.IStructuredTextSource">
+  <wiki:renderer 
+      for="zope.publisher.interfaces.browser.IBrowserPresentation" 
+      factory=".stx.StructuredTextToHTMLRenderer" />
+</wiki:sourcetype>
+
 
 </zopeConfigure>


=== zopeproducts/zwiki/interfaces.py 1.2 => 1.3 ===
--- zopeproducts/zwiki/interfaces.py:1.2	Mon Apr  7 03:15:31 2003
+++ zopeproducts/zwiki/interfaces.py	Tue Apr  8 00:15:02 2003
@@ -23,7 +23,6 @@
 from zope.app.interfaces.container import IContentContainer
 
 
-
 class IWiki(IContentContainer):
     """A simple Wiki Page container.
 
@@ -46,7 +45,7 @@
     type = TextLine(
         title=u"Source Type",
         description=u"Type of the source text, e.g. structured text",
-        default=u"plain text",
+        default=u"Plain Text",
         required=True)
 
     def append(source):
@@ -73,3 +72,43 @@
            The parents attribute is a list of unicode strings that contain the
            names of the parent wiki pages.
         """
+
+
+class IWikiSourceTypeService(Interface):
+    """ """
+
+    def get(title, default=None):
+        """Get the type interface by title. If the type was not found, return
+        default."""
+
+    def query(title):
+        """Get the type interface by title. Throw an error, if not found."""
+
+    def getAllTitles():
+        """Return a list of all titles."""
+
+    def createObject(self, title):
+        """Creates an object that implements the interface (note these are
+        just marker interfaces, so the object is minimal) that is registered
+        with the title passed."""
+
+
+class IGlobalWikiSourceTypeService(IWikiSourceTypeService):
+    """Adds some write methods to the service, so that we can reguster new
+    source types."""
+
+    def provide(title, iface):
+        """The title is the description of the source type and the interface
+        is used to recognize the type."""
+
+
+class IPlainTextSource(Interface):
+    """Marker interface for a plain text source. Note that an implementation
+    of this interface should always derive from unicode or behave like a
+    unicode class."""
+
+class IStructuredTextSource(Interface):
+    """Marker interface for a structured text source. Note that an
+    implementation of this interface should always derive from unicode or
+    behave like a unicode class."""
+


=== zopeproducts/zwiki/zwiki.py 1.7 => 1.8 ===
--- zopeproducts/zwiki/zwiki.py:1.7	Mon Apr  7 09:00:39 2003
+++ zopeproducts/zwiki/zwiki.py	Tue Apr  8 00:15:02 2003
@@ -15,7 +15,7 @@
 
 $Id$
 """
-from zope.component import getAdapter
+from zope.component import getAdapter, getService
 from zope.proxy.context import ContextWrapper
 from zope.app.content.folder import Folder
 from zope.app.traversing import getParent, objectName
@@ -40,9 +40,9 @@
 
     # See zopeproducts.zwiki.interfaces.IWikiPage
     source = u''
-
+    
     # See zopeproducts.zwiki.interfaces.IWikiPage
-    type = u'plain text'
+    type = u'Plain Text'
 
     __comments = 0