Gmane
From: Laurence Rowe <l <at> lrowe.co.uk>
Subject: Spellchecking support for kupu in plone
Newsgroups: gmane.comp.web.zope.plone.devel, gmane.comp.web.kupu.devel
Date: 2005-07-30 23:39:38 GMT (3 years, 17 weeks, 6 days, 13 hours and 29 minutes ago)
I've had a go enabling the spellchecker support for plone. Attached is a 
patch that provides the required functionality, though there are a 
couple of things missing:

* I don't understand how the archetypes multi editor support works, I 
think there needs to be a prefix in there somewhere, but I'm not sure where.

* This needs to be configurable through the plone UI so it can be turned 
off if aspell is not available. Not sure of the best way to do this. All 
that is needed is to toggle the display: None in the css, but with 
resource registries that may be more tricky now.

Of course this is too late for plone 2.1, but it would be nice to get it 
in a point release if possible.

Many thanks to guido_w for all your help with kupu.

Laurence
Index: plone/head.kupu
===================================================================
--- plone/head.kupu	(revision 15351)
+++ plone/head.kupu	(working copy)
@@ -50,6 +50,8 @@

     <script type="text/javascript" src="kupudrawers.js"
             tal:attributes="src string:${portal_url}/kupudrawers.js"> </script>
+    <script type="text/javascript" src="kupuspellchecker.js"
+            tal:attributes="src string:${portal_url}/kupuspellchecker.js"> </script>
    </tal:test>
   </kupu:part>

Index: plone/plonelibrarytool.py
===================================================================
--- plone/plonelibrarytool.py	(revision 15351)
+++ plone/plonelibrarytool.py	(working copy)
@@ -79,7 +79,7 @@

     # protect methods provided by super class KupuLibraryTool
     security.declareProtected(permissions.QueryLibraries, "getLibraries",
-                              "getPortalTypesForResourceType")
+                              "getPortalTypesForResourceType", "spellcheck")
     security.declareProtected(permissions.ManageLibraries, "addLibrary",
                               "deleteLibraries", "updateLibraries",
                               "moveUp", "moveDown")
Index: plone/librarytool.py
===================================================================
--- plone/librarytool.py	(revision 15351)
+++ plone/librarytool.py	(working copy)
@@ -19,7 +19,9 @@
 from Products.CMFCore.Expression import createExprContext
 from Products.kupu.plone.interfaces import IKupuLibraryTool
 from Products.CMFCore.utils import getToolByName
+from Products.kupu.python.spellcheck import SpellChecker, format_result

+
 class KupuError(Exception): pass

 class KupuLibraryTool(Acquisition.Implicit):
@@ -163,3 +165,18 @@
         """See IResourceTypeMapper"""
         for type in resource_types:
             del self._res_types[type]
+
+    def spellcheck(self, REQUEST, RESPONSE):
+        """Spellchecker button support fucntion"""
+        data = REQUEST.form.get('text')
+        c = SpellChecker()
+        result = c.check(data)
+        if result == None:
+            result = ''
+        else:
+            result = format_result(result)
+
+        RESPONSE.setHeader('Content-Type', 'text/xml,charset=UTF-8')
+        RESPONSE.setHeader('Content-Length', len(result))
+        RESPONSE.write(result)
+        
Index: plone/kupu_plone_layer/kupuploneinit.js
===================================================================
--- plone/kupu_plone_layer/kupuploneinit.js	(revision 15351)
+++ plone/kupu_plone_layer/kupuploneinit.js	(working copy)
@@ -156,6 +156,11 @@
         prefix+'select.kupu-tb-styles',
         prefix+'button.kupu-logo');
     kupu.registerTool('zoomtool', zoom);
+    
+    // XXX  - Needs prefix here for multi area support, but also added to the template
+    var spellchecker = new KupuSpellChecker('kupu-spellchecker-button',
+                                            'kupu_library_tool/spellcheck');
+    kupu.registerTool('spellchecker', spellchecker);

     // Use the generic beforeUnload handler if we have it:
     var beforeunloadTool = window.onbeforeunload && window.onbeforeunload.tool;
Index: plone/kupu_plone_layer/kupuplone.css.dtml
===================================================================
--- plone/kupu_plone_layer/kupuplone.css.dtml	(revision 15351)
+++ plone/kupu_plone_layer/kupuplone.css.dtml	(working copy)
@@ -195,7 +195,7 @@
 .kupu-undo {background-image: url("plonekupuimages/undo.gif");}
 .kupu-removelink {background-image: url("plonekupuimages/delete_icon.gif");}
 .kupu-removeimage {background-image: url("plonekupuimages/delete_icon.gif");}
-.kupu-spellchecker { display:none; }
+/*.kupu-spellchecker { display:none; } */

 div.kupu-drawer {
   border: solid 1px &dtml-contentViewBorderColor;;