[Checkins] SVN: zope.html/trunk/src/zope/html/ - add a few more
configuration points for the FCKeditor widget
Fred L. Drake, Jr.
fdrake at gmail.com
Tue Oct 17 14:16:19 EDT 2006
Log message for revision 70760:
- add a few more configuration points for the FCKeditor widget
- add a start at a test suite for the widget
Changed:
U zope.html/trunk/src/zope/html/tests.py
U zope.html/trunk/src/zope/html/widget.py
A zope.html/trunk/src/zope/html/widget.txt
-=-
Modified: zope.html/trunk/src/zope/html/tests.py
===================================================================
--- zope.html/trunk/src/zope/html/tests.py 2006-10-17 18:08:12 UTC (rev 70759)
+++ zope.html/trunk/src/zope/html/tests.py 2006-10-17 18:16:18 UTC (rev 70760)
@@ -3,14 +3,25 @@
"""
__docformat__ = "reStructuredText"
+import unittest
+
from zope.testing import doctest
import zope.annotation.attribute
+import zope.app.form.browser.tests.test_textareawidget
import zope.app.testing.placelesssetup
import zope.component
import zope.mimetype.types
+import zope.html.widget
+
+class FckeditorWidgetTestCase(
+ zope.app.form.browser.tests.test_textareawidget.TextAreaWidgetTest):
+
+ _WidgetFactory = zope.html.widget.FckeditorWidget
+
+
def setUp(test):
zope.app.testing.placelesssetup.setUp()
zope.component.provideAdapter(
@@ -24,5 +35,13 @@
def test_suite():
- return doctest.DocFileSuite(
- "docinfo.txt", setUp=setUp, tearDown=tearDown)
+ return unittest.TestSuite([
+ doctest.DocFileSuite(
+ "docinfo.txt",
+ setUp=setUp,
+ tearDown=tearDown),
+ doctest.DocFileSuite(
+ "widget.txt",
+ optionflags=(doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)),
+ unittest.makeSuite(FckeditorWidgetTestCase),
+ ])
Modified: zope.html/trunk/src/zope/html/widget.py
===================================================================
--- zope.html/trunk/src/zope/html/widget.py 2006-10-17 18:08:12 UTC (rev 70759)
+++ zope.html/trunk/src/zope/html/widget.py 2006-10-17 18:16:18 UTC (rev 70760)
@@ -10,6 +10,10 @@
class FckeditorWidget(zope.app.form.browser.TextAreaWidget):
+ editorWidth = 600
+ editorHeight = 400
+
+ configurationPath = "/@@/zope_fckconfig.js"
toolbarConfiguration = "zope"
def __call__(self):
@@ -21,30 +25,28 @@
# appropriate, or a per-request counter would also do nicely.
#
d = {
+ "config": self.configurationPath,
"name": self.name,
"shortname": self.name.split('.', 1)[-1],
"toolbars": self.toolbarConfiguration,
+ "width": self.editorWidth,
+ "height": self.editorHeight,
}
- # suppress the rows/cols since those are ignored anyway
- self.width = 10
- self.height = 10
textarea = super(FckeditorWidget, self).__call__()
- textarea = textarea.replace(' cols="10"', "", 1)
- textarea = textarea.replace(' rows="10"', "", 1)
+ return textarea + (self.javascriptTemplate % d)
- return textarea + (JAVASCRIPT_TEMPLATE % d)
+ # This uses a hard-coded width instead of a percentage, because
+ # the percentage doesn't seem to work in Firefox/Mozilla/Epiphany.
+ # Hopefully this will be fixed or there's some better workaround
+ # for it.
-# This uses a hard-coded width instead of a percentage, because the
-# percentage doesn't seem to work in Firefox/Mozilla/Epiphany.
-# Hopefully this will be fixed or there's some better workaround for
-# it.
-
-JAVASCRIPT_TEMPLATE = '''
+ javascriptTemplate = '''
<script type="text/javascript" language="JavaScript">
-var oFCKeditor_%(shortname)s = new FCKeditor("%(name)s", 600, 400, "%(toolbars)s");
+var oFCKeditor_%(shortname)s = new FCKeditor(
+ "%(name)s", %(width)d, %(height)d, "%(toolbars)s");
oFCKeditor_%(shortname)s.BasePath = "/@@/fckeditor/";
- oFCKeditor_%(shortname)s.Config["CustomConfigurationsPath"] = "/@@/zope_fckconfig.js";
+ oFCKeditor_%(shortname)s.Config["CustomConfigurationsPath"] = "%(config)s";
oFCKeditor_%(shortname)s.ReplaceTextarea();
</script>
'''
Added: zope.html/trunk/src/zope/html/widget.txt
===================================================================
--- zope.html/trunk/src/zope/html/widget.txt 2006-10-17 18:08:12 UTC (rev 70759)
+++ zope.html/trunk/src/zope/html/widget.txt 2006-10-17 18:16:18 UTC (rev 70760)
@@ -0,0 +1,39 @@
+==============================
+(X)HTML fragment editor widget
+==============================
+
+The widget included in this package is a simple application of the
+FCKeditor control. It is only expected to work for fragments, not for
+arbitrary documents. Let's create a field and a widget::
+
+ >>> from zope.html import field
+ >>> from zope.html import widget
+ >>> from zope.publisher import browser
+
+ >>> class Context(object):
+ ... sample = u""
+
+ >>> myfield = field.XhtmlFragment(
+ ... __name__="sample",
+ ... title=u"Sample Field",
+ ... ).bind(Context())
+
+ >>> request = browser.TestRequest()
+ >>> mywidget = widget.FckeditorWidget(myfield, request)
+ >>> mywidget.setPrefix("form")
+
+ >>> mywidget.configurationPath = "/myconfig.js"
+ >>> mywidget.editorWidth = 360
+ >>> mywidget.editorHeight = 200
+ >>> mywidget.toolbarConfiguration = "mytoolbars"
+
+ >>> print mywidget()
+ <textarea...></textarea>
+ <script...
+ "form.sample", 360, 200, "mytoolbars");
+ ...Config["CustomConfigurationsPath"] = "/myconfig.js";
+ ...
+ </script>
+ <BLANKLINE>
+
+ >>> print mywidget()
Property changes on: zope.html/trunk/src/zope/html/widget.txt
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
More information about the Checkins
mailing list