[KSS-checkins] r47376 - in kukit/kss.base/trunk: . kss/base
jvloothuis at codespeak.net
jvloothuis at codespeak.net
Wed Oct 10 11:40:07 CEST 2007
Author: jvloothuis
Date: Wed Oct 10 11:40:07 2007
New Revision: 47376
Added:
kukit/kss.base/trunk/kss/base/config.py
kukit/kss.base/trunk/kss/base/corecommands.txt
kukit/kss.base/trunk/kss/base/registry.txt
Removed:
kukit/kss.base/trunk/kss/base/pluginregistry.txt
Modified:
kukit/kss.base/trunk/kss/base/README.txt
kukit/kss.base/trunk/kss/base/commands.py
kukit/kss.base/trunk/kss/base/commandset.py
kukit/kss.base/trunk/kss/base/corecommands.py
kukit/kss.base/trunk/kss/base/plugin.py
kukit/kss.base/trunk/kss/base/registry.py
kukit/kss.base/trunk/kss/base/tests.py
kukit/kss.base/trunk/setup.py
Log:
Refactored the registries and added more tests
Modified: kukit/kss.base/trunk/kss/base/README.txt
==============================================================================
--- kukit/kss.base/trunk/kss/base/README.txt (original)
+++ kukit/kss.base/trunk/kss/base/README.txt Wed Oct 10 11:40:07 2007
@@ -112,24 +112,6 @@
The thing that makes this interesting is the actual command sets. Take a look
at the core commands for a better understanding of the usage pattern.
-Core commands
--------------
-
-The core commands wrap all standard KSS actions that are always available.
-These do not contain any effects and focus mostly on DOM manipulation.
-
-First we will need to create our command set.
-
- >>> from kss.base.corecommands import KSSCoreCommands
- >>> commands = KSSCommands()
- >>> core = KSSCoreCommands(commands)
-
-Now we will look at the individual methods provided by the core commands.
-
- >>> core.replaceInnerHTML(CSS('div'), 'some <h1>html</h1>')
- >>> commands.render()
- '...replaceInnerHTML...some &lt;h1&gt;html&lt;/h1&gt;...'
-
Using command sets
==================
@@ -140,6 +122,7 @@
We will now demonstrate this in the next example. First we need to load the
registry.
+ >>> from kss.base.corecommands import KSSCoreCommands
>>> from kss.base.registry import command_set_registry
Now we can register our command set. For more information about the registry look at the documentation of kss.pluginregistry.
Modified: kukit/kss.base/trunk/kss/base/commands.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/commands.py (original)
+++ kukit/kss.base/trunk/kss/base/commands.py Wed Oct 10 11:40:07 2007
@@ -55,6 +55,9 @@
def lookup(self, name):
return command_set_registry.get(name)(self)
+ def clear(self):
+ self.commands = []
+
def __str__(self):
def format_options(options):
if not options:
Modified: kukit/kss.base/trunk/kss/base/commandset.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/commandset.py (original)
+++ kukit/kss.base/trunk/kss/base/commandset.py Wed Oct 10 11:40:07 2007
@@ -1,21 +0,0 @@
-class CommandSetRegistry(object):
- def __init__(self):
- self._sets = {}
-
- def register(self, name, factory):
- if name in self._sets:
- raise KeyError('Duplicate registration for name: %s' % name)
- self._sets[name] = factory
-
- def unregister(self, name):
- del self._sets[name]
-
- def get(self, name):
- return self._sets[name]
-
- def items(self):
- return self._sets.iteritems()
-
-
-class PluginRegistry(CommandSetRegistry):
- pass
Added: kukit/kss.base/trunk/kss/base/config.py
==============================================================================
--- (empty file)
+++ kukit/kss.base/trunk/kss/base/config.py Wed Oct 10 11:40:07 2007
@@ -0,0 +1,48 @@
+import os
+
+from kss.base.plugin import Plugin, javascripts_from
+from kss.base.corecommands import KSSCoreCommands
+from kss.base.coreselectors import CSS, HTMLId, SameNode, ParentNode
+
+kukit_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'kukit')
+
+core_js = ['utils.js',
+ 'errors.js',
+ 'oper.js',
+ 'kukit.js',
+ 'tokenizer.js',
+ 'providerreg.js',
+ 'resourcedata.js',
+ 'kssparser.js',
+ 'eventreg.js',
+ 'actionreg.js',
+ 'dom.js',
+ 'commandreg.js',
+ 'serveraction.js',
+ 'requestmanager.js',
+ 'commandprocessor.js',
+ 'selectorreg.js',
+ 'forms.js',
+ 'plugin.js',
+ ]
+
+
+class KSSCore(Plugin):
+ '''The KSS core plugin has all the standard functionality'''
+
+ priority = -1000
+
+ javascripts = [os.path.join(kukit_dir, 'kukit', js) for js in core_js]
+
+ extra_javascripts = javascripts_from(os.path.join(kukit_dir, '3rd_party'))
+
+ commandsets = {
+ 'core': KSSCoreCommands,
+ }
+
+ selectors = [CSS, HTMLId, SameNode, ParentNode]
+
+ # OPTIONAL!
+ events={}
+ actions=[]
+ value_providers = []
Modified: kukit/kss.base/trunk/kss/base/corecommands.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/corecommands.py (original)
+++ kukit/kss.base/trunk/kss/base/corecommands.py Wed Oct 10 11:40:07 2007
@@ -8,10 +8,92 @@
def replaceHTML(self, selector, value):
self.commands.add('replaceHTML', selector, html=value)
- def insert_html_after(self, selector, value):
+
+ def setAttribute(self, selector, name, value):
+ self.commands.add('setAttribute', selector, name=name, value=value)
+
+ def setStyle(self, selector, name, value):
+ if ' ' in name:
+ raise ValueError('Style properites cannot contain spaces')
+ self.commands.add('setStyle', selector, name=name, value=value)
+
+
+ def insertHTMLAfter(self, selector, value):
self.commands.add('insertHTMLAfter', selector, html=value)
- def insert_html_as_first_child(self, selector, value):
+ def insertHTMLAsFirstChild(self, selector, value):
self.commands.add('insertHTMLAsFirstChild', selector, html=value)
-
-
+
+ def insertHTMLAsLastChild(self, selector, value):
+ self.commands.add('insertHTMLAsLastChild', selector, html=value)
+
+ def insertHTMLBefore(self, selector, value):
+ self.commands.add('insertHTMLBefore', selector, html=value)
+
+
+
+ def clearChildNodes(self, selector):
+ self.commands.add('clearChildNodes', selector)
+
+ def deleteNode(self, selector):
+ self.commands.add('deleteNode', selector)
+
+ def deleteNodeAfter(self, selector):
+ self.commands.add('deleteNodeAfter', selector)
+
+ def deleteNodeBefore(self, selector):
+ self.commands.add('deleteNodeBefore', selector)
+
+
+
+ def copyChildNodesFrom(self, selector, id):
+ self.commands.add('copyChildNodesFrom', selector, html_id=id)
+
+ def moveNodeAfter(self, selector, id):
+ self.commands.add('moveNodeAfter', selector, html_id=id)
+
+ def moveNodeBefore(self, selector, id):
+ self.commands.add('moveNodeBefore', selector, html_id=id)
+
+ def copyChildNodesTo(self, selector, id):
+ self.commands.add('copyChildNodesTo', selector, html_id=id)
+
+
+
+ def setStateVar(self, varname, value):
+ selector = None
+ self.commands.add('setStateVar', selector, varname=varname, value=value)
+
+ def triggerEvent(self, name, **kw):
+ self.commands.add('triggerEvent', name=name, **kwargs)
+
+ def toggleClass(self, selector, *arg, **kw):
+ ##def toggleClass(self, selector, value):
+ """ see interfaces.py """
+ # BBB 4 months, until 2007-10-18
+ value = BBB_classParms('toggleClass', *arg, **kw)
+
+ command = self.commands.addCommand('toggleClass', selector)
+ data = command.addParam('value', value)
+
+ def addClass(self, selector, *arg, **kw):
+ ##def addClass(self, selector, name):
+ """ see interfaces.py """
+ # BBB 4 months, until 2007-10-18
+ value = BBB_classParms('addClass', *arg, **kw)
+
+ command = self.commands.addCommand('addClass', selector)
+ data = command.addParam('value', value)
+
+ def removeClass(self, selector, *arg, **kw):
+ ##def removeClass(self, selector, name):
+ """ see interfaces.py """
+ # BBB 4 months, until 2007-10-18
+ value = BBB_classParms('removeClass', *arg, **kw)
+
+ command = self.commands.addCommand('removeClass', selector)
+ data = command.addParam('value', value)
+
+ def focus(self, selector):
+ """ see interfaces.py """
+ command = self.commands.addCommand('focus', selector)
Added: kukit/kss.base/trunk/kss/base/corecommands.txt
==============================================================================
--- (empty file)
+++ kukit/kss.base/trunk/kss/base/corecommands.txt Wed Oct 10 11:40:07 2007
@@ -0,0 +1,40 @@
+=============
+Core commands
+=============
+
+The core commands wrap all standard KSS actions that are always available.
+These do not contain any effects and focus mostly on DOM manipulation.
+
+First we will need to create our command set.
+
+ >>> from kss.base.corecommands import KSSCoreCommands
+ >>> from kss.base import KSSCommands
+ >>> from kss.base.coreselectors import CSS
+
+ >>> commands = KSSCommands()
+ >>> core = KSSCoreCommands(commands)
+
+Now we will look at the individual methods provided by the core commands.
+
+ >>> core.replaceInnerHTML(CSS('div'), 'some <h1>html</h1>')
+ >>> commands.render()
+ '...replaceInnerHTML...some &lt;h1&gt;html&lt;/h1&gt;...'
+
+
+Set attribute
+-------------
+
+ >>> commands.clear()
+ >>> core.setAttribute(CSS('div'), 'some name', 'some value')
+ >>> print commands
+ setAttribute(css('div'), name='some name', value='some value')
+
+Set style
+---------
+
+ >>> commands.clear()
+ >>> core.setStyle(CSS('div'), 'somename', 'some value')
+ >>> print commands
+ setStyle(css('div'), name='somename', value='some value')
+
+
Modified: kukit/kss.base/trunk/kss/base/plugin.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/plugin.py (original)
+++ kukit/kss.base/trunk/kss/base/plugin.py Wed Oct 10 11:40:07 2007
@@ -45,51 +45,3 @@
def activated_plugins():
return plugin_registry.items()
-
-
-# !TODO: Move to a seperate file
-from kss.base.corecommands import KSSCoreCommands
-from kss.base.coreselectors import CSS, HTMLId, SameNode, ParentNode
-
-kukit_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'kukit')
-
-core_js = ['utils.js',
- 'errors.js',
- 'oper.js',
- 'kukit.js',
- 'tokenizer.js',
- 'providerreg.js',
- 'resourcedata.js',
- 'kssparser.js',
- 'eventreg.js',
- 'actionreg.js',
- 'dom.js',
- 'commandreg.js',
- 'serveraction.js',
- 'requestmanager.js',
- 'commandprocessor.js',
- 'selectorreg.js',
- 'forms.js',
- 'plugin.js',
- ]
-
-
-class KSSCore(Plugin):
- '''The KSS core plugin has all the standard functionality'''
-
- priority = -1000
-
- javascripts = [os.path.join(kukit_dir, 'kukit', js) for js in core_js]
-
- extra_javascripts = javascripts_from(os.path.join(kukit_dir, '3rd_party'))
-
- commandsets = {
- 'core': KSSCoreCommands,
- }
-
- selectors = [CSS, HTMLId, SameNode, ParentNode]
-
- # OPTIONAL!
- events={}
- actions=[]
- value_providers = []
Deleted: /kukit/kss.base/trunk/kss/base/pluginregistry.txt
==============================================================================
--- /kukit/kss.base/trunk/kss/base/pluginregistry.txt Wed Oct 10 11:40:07 2007
+++ (empty file)
@@ -1,67 +0,0 @@
-===================
-KSS Plugin Registry
-===================
-
-The plugin registry is used so that extra plugins are easy to use. All
-registries can be easily queried and modified using the provided api.
-
-Command Set Registry
-====================
-
-One of the main features of KSS are the command sets. These wrap the transport
-protocol for easier usage. To make sure all access to the commandsets are
-convenient we provide a registry.
-
-Using the registry is pretty simple.
-
- >>> from kss.base.registry import command_set_registry
-
-First we will create a simple factory for our command set. Note that any
-callable object will do. For more information on command sets look at the
-documentation in kss.commands.
-
- >>> def test_command_set_factory(commands):
- ... pass
-
-We can register a command set by passing in the factory and a name.
-
- >>> command_set_registry.register('test', test_command_set_factory)
-
-The name is used as a unique identifier to lookup the command set factory.
-When you try to register a factory under the same name you will get an error.
-
- >>> command_set_registry.register('test', test_command_set_factory)
- Traceback (most recent call last):
- ...
- KeyError: ...
-
-This avoids any accidental overrides. If you want to override a command you
-can unregister it first.
-
- >>> command_set_registry.unregister('test')
-
-Unregistering the same thing twice will throw a KeyError.
-
- >>> command_set_registry.unregister('test')
- Traceback (most recent call last):
- ...
- KeyError: ...
-
-This is because we cannot unregister what is not there.
-
-Now that the registry is clean we can safely register our command set again.
-
- >>> command_set_registry.register('test', test_command_set_factory)
-
-To use a command set we will need to get it from the registry. Let us load the
-previously defined `test` set.
-
- >>> command_set_registry.get('test') is test_command_set_factory
- True
-
-Trying to load a command set which is not defined will result in a key error.
-
- >>> command_set_registry.get('does-not-exist')
- Traceback (most recent call last):
- ...
- KeyError: ...
Modified: kukit/kss.base/trunk/kss/base/registry.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/registry.py (original)
+++ kukit/kss.base/trunk/kss/base/registry.py Wed Oct 10 11:40:07 2007
@@ -1,4 +1,20 @@
-from kss.base.commandset import CommandSetRegistry
+class Registry(object):
+ def __init__(self):
+ self._items = {}
-command_set_registry = CommandSetRegistry()
-plugin_registry = CommandSetRegistry()
+ def register(self, name, factory):
+ if name in self._items:
+ raise KeyError('Duplicate registration for name: %s' % name)
+ self._items[name] = factory
+
+ def unregister(self, name):
+ del self._items[name]
+
+ def get(self, name):
+ return self._items[name]
+
+ def items(self):
+ return self._items.iteritems()
+
+command_set_registry = Registry()
+plugin_registry = Registry()
Added: kukit/kss.base/trunk/kss/base/registry.txt
==============================================================================
--- (empty file)
+++ kukit/kss.base/trunk/kss/base/registry.txt Wed Oct 10 11:40:07 2007
@@ -0,0 +1,72 @@
+==============
+KSS Registries
+==============
+
+KSS can be extendend in a few different ways. To make these things
+work we have a few different registries.
+
+The registries are all instances of a simple base class. Using these
+is pretty simple.
+
+ >>> from kss.base.registry import Registry
+
+We will now demonstrate the working of this registry with an sample
+command set.
+
+ >>> command_set_registry = Registry()
+
+First we will create a simple factory function for our command
+set. Note that any callable object will do. For more information on
+command sets look at the documentation in kss.commands.
+
+ >>> def test_command_set_factory(commands):
+ ... pass
+
+We can register a command set by passing in the factory and a name.
+
+ >>> command_set_registry.register('test', test_command_set_factory)
+
+The name is used as a unique identifier to lookup the command set factory.
+When you try to register a factory under the same name you will get an error.
+
+ >>> command_set_registry.register('test', test_command_set_factory)
+ Traceback (most recent call last):
+ ...
+ KeyError: ...
+
+This avoids any accidental overrides. If you want to override a command you
+can unregister it first.
+
+ >>> command_set_registry.unregister('test')
+
+Unregistering the same thing twice will throw a KeyError.
+
+ >>> command_set_registry.unregister('test')
+ Traceback (most recent call last):
+ ...
+ KeyError: ...
+
+This is because we cannot unregister what is not there.
+
+Now that the registry is clean we can safely register our command set again.
+
+ >>> command_set_registry.register('test', test_command_set_factory)
+
+To use a command set we will need to get it from the registry. Let us load the
+previously defined `test` set.
+
+ >>> command_set_registry.get('test') is test_command_set_factory
+ True
+
+Trying to load a command set which is not defined will result in a key error.
+
+ >>> command_set_registry.get('does-not-exist')
+ Traceback (most recent call last):
+ ...
+ KeyError: ...
+
+Registries can list theirs registered items.
+
+ >>> list(command_set_registry.items())
+ [('test', <function test_command_set_factory at ...>)]
+
Modified: kukit/kss.base/trunk/kss/base/tests.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/tests.py (original)
+++ kukit/kss.base/trunk/kss/base/tests.py Wed Oct 10 11:40:07 2007
@@ -5,7 +5,7 @@
suite = unittest.TestSuite((
doctest.DocFileSuite(
'README.txt', 'selectors.txt',
- 'pluginregistry.txt',
+ 'registry.txt', 'corecommands.txt',
package='kss.base',
optionflags=doctest.ELLIPSIS|doctest.REPORT_ONLY_FIRST_FAILURE,
),
Modified: kukit/kss.base/trunk/setup.py
==============================================================================
--- kukit/kss.base/trunk/setup.py (original)
+++ kukit/kss.base/trunk/setup.py Wed Oct 10 11:40:07 2007
@@ -26,7 +26,7 @@
],
entry_points={
'kss.plugin': [
- 'kss-core=kss.base.plugin:KSSCore'
+ 'kss-core=kss.base.config:KSSCore'
],
'console_scripts': [
'kssconcatjs=kss.base.utils:KSSConcatJs'
More information about the Kukit-checkins
mailing list