Author: bree
Date: Sun Mar 12 12:52:06 2006
New Revision: 2611
Removed:
azax/branches/plugin/plugins/browser/
Modified:
azax/branches/plugin/azaxview.py
azax/branches/plugin/plugins/__init__.py
azax/branches/plugin/plugins/command.py
azax/branches/plugin/plugins/configure.py
azax/branches/plugin/plugins/configure.zcml
azax/branches/plugin/plugins/directives.py
azax/branches/plugin/plugins/plugin.py
azax/branches/plugin/tests/test_azaxview.py
Log:
Progress with command plugins
Modified: azax/branches/plugin/azaxview.py
==============================================================================
--- azax/branches/plugin/azaxview.py (original)
+++ azax/branches/plugin/azaxview.py Sun Mar 12 12:52:06 2006
@@ -24,6 +24,7 @@
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from Products.Five import BrowserView
from unicode_quirks import force_unicode
+from plugins import Command
import htmlentitydefs
import re
@@ -94,6 +95,7 @@
class AzaxCommand:
def __init__(self, name, selector):
+ Command.checkRegistered(name)
if isinstance(selector, basestring):
self.selector = selector
self.selectorType = ''
Modified: azax/branches/plugin/plugins/__init__.py
==============================================================================
--- azax/branches/plugin/plugins/__init__.py (original)
+++ azax/branches/plugin/plugins/__init__.py Sun Mar 12 12:52:06 2006
@@ -2,3 +2,5 @@
Module init
'''
+from plugin import AzaxPluginError
+from command import Command
Modified: azax/branches/plugin/plugins/command.py
==============================================================================
--- azax/branches/plugin/plugins/command.py (original)
+++ azax/branches/plugin/plugins/command.py Sun Mar 12 12:52:06 2006
@@ -1,14 +1,14 @@
-from plugin import Plugin, baseclass_singleton_property
+from plugin import Plugin
class Command(Plugin):
'''The command plugin
'''
- def __init__(self, name, jsfile, method):
- Plugin.__init__(self, name)
- self.jsfile = jsfile
- self.method = method
+ plugins = {}
-Command.__plugin_baseclass__ = Command
+ def __init__(self, name, jsresource):
+ Plugin.__init__(self, name, jsresource)
+
+Command.__pluginclass__ = Command
Modified: azax/branches/plugin/plugins/configure.py
==============================================================================
--- azax/branches/plugin/plugins/configure.py (original)
+++ azax/branches/plugin/plugins/configure.py Sun Mar 12 12:52:06 2006
@@ -5,13 +5,7 @@
class AzaxConfigurationError(Exception):
pass
-def registerCommand(_context, name, jsfile, method):
+def registerCommand(_context, name, jsresource=None):
- jsfile = _context.path(jsfile)
-
- if not os.path.exists(jsfile):
- raise AzaxConfigurationError, 'jsfile "%s" does not exist.' % (jsfile,
)
-
- command = Command(name, jsfile, method)
+ command = Command(name, jsresource)
command.register()
-
Modified: azax/branches/plugin/plugins/configure.zcml
==============================================================================
--- azax/branches/plugin/plugins/configure.zcml (original)
+++ azax/branches/plugin/plugins/configure.zcml Sun Mar 12 12:52:06 2006
@@ -1,15 +1,71 @@
<configure xmlns="http://namespaces.zope.org/zope"
- xmlns:azax="http://namespaces.zope.org/azax">
+ xmlns:browser="http://namespaces.zope.org/browser"
+ xmlns:azax="http://namespaces.zope.org/azax"
+ >
- <!-- custom components should omit the next line -->
- <include file="meta.zcml" />
+ <!-- example plugin registration
+
+ <browser:resource
+ file="browser/my_plugins.js"
+ name="my_plugins.js"
+ />
- <!-- register core plugins -->
-
- <azax:registerCommand
- name = "setHtmlAsChild"
- jsfile = "browser/corecommands.js"
- method = "setHtmlAsChild"
- />
+ <azax:registerCommand
+ name="myCustomCommand"
+ jsresource="/++resource++my_plugins.js"
+ />
+ -->
+
+ <!-- custom components should not include the next line -->
+ <include file="meta.zcml" />
+
+ <!-- register core plugins
+ jsresource is omitted since these are defined in the core
+ -->
+
+ <azax:registerCommand
+ name="setHtmlAsChild"
+ />
+
+ <azax:registerCommand
+ name="setAttribute"
+ />
+
+ <azax:registerCommand
+ name="addAfter"
+ />
+
+ <azax:registerCommand
+ name="removeNextSibling"
+ />
+
+ <azax:registerCommand
+ name="removePreviousSibling"
+ />
+
+ <azax:registerCommand
+ name="removeNode"
+ />
+
+ <azax:registerCommand
+ name="clearChildren"
+ />
+
+ <azax:registerCommand
+ name="moveNodeAfter"
+ />
+
+ <azax:registerCommand
+ name="copyChildrenFrom"
+ />
+
+ <azax:registerCommand
+ name="copyChildrenTo"
+ />
+
+ <azax:registerCommand
+ name="executeCode"
+ />
+
</configure>
Modified: azax/branches/plugin/plugins/directives.py
==============================================================================
--- azax/branches/plugin/plugins/directives.py (original)
+++ azax/branches/plugin/plugins/directives.py Sun Mar 12 12:52:06 2006
@@ -10,14 +10,8 @@
required=True,
)
- jsfile = TextLine(
- title=u"Javascript file",
- description=u"The javascript file path where the method is in.",
- required=True,
- )
-
- method = TextLine(
- title=u"Method name",
- description=u"The name of the javascript method",
- required=True,
+ jsresource = TextLine(
+ title=u"Javascript resource",
+ description=u"The javascript resource that defines the plugin",
+ required=False,
)
Modified: azax/branches/plugin/plugins/plugin.py
==============================================================================
--- azax/branches/plugin/plugins/plugin.py (original)
+++ azax/branches/plugin/plugins/plugin.py Sun Mar 12 12:52:06 2006
@@ -1,58 +1,47 @@
-import copy
-
class AzaxPluginError(Exception):
pass
-# --
-# Metaclass magic
-# --
-
-class baseclass_singleton_property(object):
- '''A singleton property on the baseclass, with default value
- '''
+class JsResource(object):
- def __init__(self, name, default=None):
+ def __init__(self, name):
self.name = name
- self.default = default
- self.__doc__ = 'Singleton property for "%s"' % name
+ self.content = []
- def __get__(self, obj, cls):
- try:
- return getattr(cls.__plugin_baseclass__, '_' + self.name)
- except AttributeError:
- # set the default value, (make sure it's cloned)
- val = copy.deepcopy(self.default)
- self.__set__(cls, val)
- return getattr(cls.__plugin_baseclass__, '_' + self.name)
-
- def __set__(self, obj, value):
- setattr(obj.__plugin_baseclass__, '_' + self.name, value)
-
- def __delete__(self, obj):
- delattr(obj.__plugin_baseclass__, '_' + self.name)
-
-# --
-# The base plugin class
-# --
-
class Plugin(object):
+ 'The base plugin class'
+
+ jsresources = {} # the js resource files
+ plugins = None # must be set to {} in the plugin class
+ __pluginclass__ = None # must be set to the plugin class
- __plugin_baseclass__ = None # Need to overwrite this
- # ... it should be set to the plugin class, e.g. Command, Event,
etc.
- # That's where all the singleton properties will be created.
-
- plugins = baseclass_singleton_property('plugins', {})
-
- def __init__(self, name):
+ def __init__(self, name, jsresource):
self.name = name
+ self.jsresource = jsresource
def register(self):
'''The registration method
This can be extended for a given plugin type by adding more
- baseclass_singleton_properties, etc.
+ class singleton properties, etc.
'''
if self.name in self.plugins:
- raise AzaxPluginError, 'Duplicate registration attempt for plugin
"%s" of class "%s"' % (self.name, self.__plugin_baseclass__.__name__)
+ raise AzaxPluginError, 'Duplicate registration attempt for plugin
"%s" of class "%s"' % (self.name, self.__pluginclass__.__name__)
self.plugins[self.name] = self
+ if self.jsresource is not None:
+ try:
+ r = self.jsresources[self.jsresource]
+ except KeyError:
+ r = self.jsresources[self.jsresource] =
JsResource(self.jsresource)
+ r.content.append((self.__pluginclass__, self.name))
+
+ def isRegistered(cls, name):
+ 'Tells if name is a registered plugin for the pluginclass'
+ return name in cls.plugins
+ isRegistered = classmethod(isRegistered)
+
+ def checkRegistered(cls, name):
+ 'Check if name is a registered plugin and raise error otherwise'
+ if not cls.isRegistered(name):
+ raise AzaxPluginError, '"%s" is not a registered plugin for plugin
class "%s"' % (name, cls.__pluginclass__.__name__)
+ checkRegistered = classmethod(checkRegistered)
Modified: azax/branches/plugin/tests/test_azaxview.py
==============================================================================
--- azax/branches/plugin/tests/test_azaxview.py (original)
+++ azax/branches/plugin/tests/test_azaxview.py Sun Mar 12 12:52:06 2006
@@ -74,6 +74,22 @@
provides="zope.app.traversing.interfaces.ITraverser"
/-->
</configure>'''))
+ load_config('configure.zcml', package=Products.azax.plugins)
+
+ def beforeTearDown(self):
+ from zope.app.tests.placelesssetup import tearDown
+ tearDown()
+ try:
+ import Products.Five
+ except ImportError:
+ # probably zope 3
+ pass
+ else:
+ import Products.Five.zcml
+ Products.Five.zcml._context = None
+ from Products.azax import plugins
+ plugins.Command.plugins = {}
+ plugins.plugin.jsresources = {}
class TestAzaxView(AzaxViewTestCase):
@@ -84,10 +100,10 @@
def test_addCommand(self):
view = self.view
- command = view.addCommand('name', 'selector')
+ command = view.addCommand('setHtmlAsChild', 'selector')
commands = view.getCommands()
self.assertEqual(len(commands), 1)
- self.assertEqual(command.getName(), 'name')
+ self.assertEqual(command.getName(), 'setHtmlAsChild')
self.assertEqual(command.getSelector(), 'selector')
params = command.getParams()
self.assertEqual(len(params), 0)
--
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins