Author: bree
Date: Fri Mar 10 10:53:18 2006
New Revision: 2570

Added:
   azax/branches/plugin/meta.zcml
   azax/branches/plugin/plugins/
   azax/branches/plugin/plugins/__init__.py
   azax/branches/plugin/plugins/browser/
   azax/branches/plugin/plugins/browser/corecommands.js
   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/meta.zcml
   azax/branches/plugin/plugins/plugin.py
Modified:
   azax/branches/plugin/configure.zcml
Log:
configuration for plugins, server side (command plugin only)

Modified: azax/branches/plugin/configure.zcml
==============================================================================
--- azax/branches/plugin/configure.zcml (original)
+++ azax/branches/plugin/configure.zcml Fri Mar 10 10:53:18 2006
@@ -1,7 +1,7 @@
 <configure xmlns="http://namespaces.zope.org/zope";
            xmlns:browser="http://namespaces.zope.org/browser";
            xmlns:five="http://namespaces.zope.org/five";>
-
+  
   <browser:resource
     file="kukit/3rd_party/sarissa.js"
     name="sarissa.js"

Added: azax/branches/plugin/meta.zcml
==============================================================================
--- (empty file)
+++ azax/branches/plugin/meta.zcml      Fri Mar 10 10:53:18 2006
@@ -0,0 +1,6 @@
+<configure
+     xmlns="http://namespaces.zope.org/meta";>
+
+   <include package=".plugins" />
+
+</configure>

Added: azax/branches/plugin/plugins/__init__.py
==============================================================================
--- (empty file)
+++ azax/branches/plugin/plugins/__init__.py    Fri Mar 10 10:53:18 2006
@@ -0,0 +1,4 @@
+'''\
+Module init
+'''
+

Added: azax/branches/plugin/plugins/browser/corecommands.js
==============================================================================
--- (empty file)
+++ azax/branches/plugin/plugins/browser/corecommands.js        Fri Mar 10 
10:53:18 2006
@@ -0,0 +1,42 @@
+
+/* so this is the js file with our core commands.*/
+
+/* does not work yet of course... */
+
+/*
+So the question is left if we do something like
+
+*/
+
+kukit.registerCommand('setHtmlAsChild', function(node, command_data)
+{
+    Sarissa.clearChildNodes(node);
+    var childNodes = command_data['html'].childNodes;
+    kukit.dom.appendChildren(childNodes, node);
+    kukit.setupEvents(node);
+}
+)
+
+/* ... in this case the "method" can be omitted from the zcml
+directive,
+
+or we do something like
+*/
+
+kukit.setHtmlAsChild = function(node, command_data) {
+
+}
+
+/* and in this case the method property would be like
+
+      method="kukit.setHtmlAsChild"
+
+   or in the case we are talking about a custom component
+   registration, "my_custom_namespace" instead of "kukit".
+
+   Then the registerCommand would be implemented in the
+   same way but also the registerCommand calls
+   would be autogenerated.
+   
+*/
+

Added: azax/branches/plugin/plugins/command.py
==============================================================================
--- (empty file)
+++ azax/branches/plugin/plugins/command.py     Fri Mar 10 10:53:18 2006
@@ -0,0 +1,14 @@
+
+from plugin import Plugin, baseclass_singleton_property
+
+class Command(Plugin):
+    '''The command plugin
+
+    '''
+
+    def __init__(self, name, jsfile, method):
+        Plugin.__init__(self, name)
+        self.jsfile = jsfile
+        self.method = method
+
+Command.__plugin_baseclass__ = Command

Added: azax/branches/plugin/plugins/configure.py
==============================================================================
--- (empty file)
+++ azax/branches/plugin/plugins/configure.py   Fri Mar 10 10:53:18 2006
@@ -0,0 +1,17 @@
+
+import os.path
+from command import Command
+
+class AzaxConfigurationError(Exception):
+    pass
+
+def registerCommand(_context, name, jsfile, method):
+
+    jsfile = _context.path(jsfile)
+    
+    if not os.path.exists(jsfile):
+        raise AzaxConfigurationError, 'jsfile "%s" does not exist.' % (jsfile, 
)
+
+    command = Command(name, jsfile, method)
+    command.register()
+    

Added: azax/branches/plugin/plugins/configure.zcml
==============================================================================
--- (empty file)
+++ azax/branches/plugin/plugins/configure.zcml Fri Mar 10 10:53:18 2006
@@ -0,0 +1,15 @@
+<configure xmlns="http://namespaces.zope.org/zope";
+     xmlns:azax="http://namespaces.zope.org/azax";>
+ 
+  <!-- custom components should omit the next line -->
+  <include file="meta.zcml" />
+
+  <!-- register core plugins -->
+
+  <azax:registerCommand
+        name = "setHtmlAsChild"
+        jsfile = "browser/corecommands.js"
+        method = "setHtmlAsChild"
+        />
+  
+</configure>

Added: azax/branches/plugin/plugins/directives.py
==============================================================================
--- (empty file)
+++ azax/branches/plugin/plugins/directives.py  Fri Mar 10 10:53:18 2006
@@ -0,0 +1,23 @@
+from zope.interface import Interface
+from zope.schema import TextLine
+
+class IRegisterCommandDirective(Interface):
+    'Register an AZAX command plugin'
+    
+    name = TextLine(
+         title=u"Name",
+         description=u"The name of the command plugin.",
+         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,
+         )

Added: azax/branches/plugin/plugins/meta.zcml
==============================================================================
--- (empty file)
+++ azax/branches/plugin/plugins/meta.zcml      Fri Mar 10 10:53:18 2006
@@ -0,0 +1,12 @@
+<configure
+     xmlns="http://namespaces.zope.org/meta";>
+ 
+   <directives namespace="http://namespaces.zope.org/azax";>
+     <directive
+       name="registerCommand"
+       schema=".directives.IRegisterCommandDirective"
+       handler=".configure.registerCommand"
+       />
+   </directives>
+  
+</configure>

Added: azax/branches/plugin/plugins/plugin.py
==============================================================================
--- (empty file)
+++ azax/branches/plugin/plugins/plugin.py      Fri Mar 10 10:53:18 2006
@@ -0,0 +1,58 @@
+
+import copy
+
+class AzaxPluginError(Exception):
+    pass
+    
+# --
+# Metaclass magic
+# --
+    
+class baseclass_singleton_property(object):
+    '''A singleton property on the baseclass, with default value
+    '''
+
+    def __init__(self, name, default=None):
+        self.name = name
+        self.default = default
+        self.__doc__ = 'Singleton property for "%s"' % name
+
+    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):
+    
+    __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):
+        self.name = name
+    
+    def register(self):
+        '''The registration method
+
+        This can be extended for a given plugin type by adding more
+        baseclass_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__)
+        self.plugins[self.name] = self
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to