Author: jvloothuis
Date: Sun May 13 19:00:42 2007
New Revision: 43317
Modified:
kukit/kss.commands/trunk/kss/commands/README.txt
kukit/kss.commands/trunk/kss/commands/commands.py
kukit/kss.commands/trunk/kss/commands/corecommands.py
kukit/kss.commands/trunk/setup.py
Log:
Integrated the kss.pluginregistry with the command renderer. This makes it
possible to easily load command sets.
Changed naming of core command method to lowercase with underscores to make it
more Pythonic
Modified: kukit/kss.commands/trunk/kss/commands/README.txt
==============================================================================
--- kukit/kss.commands/trunk/kss/commands/README.txt (original)
+++ kukit/kss.commands/trunk/kss/commands/README.txt Sun May 13 19:00:42 2007
@@ -93,8 +93,35 @@
Now we will look at the individual methods provided by the core commands.
- >>> core.replaceInnerHTML(CSS('div'), 'some <h1>html</h1>')
+ >>> core.replace_inner_html(CSS('div'), 'some <h1>html</h1>')
>>> commands.render()
'...replaceInnerHTML...some <h1>html</h1>...'
-
+Using command sets
+==================
+
+In the previous examples we saw how to load command sets directly. Normally we
+do not need to do this. This is because the command renderer can also look
+them up by name. This is done by using the KSS plugin registry.
+
+We will now demonstrate this in the next example. First we need to load the
+registry.
+
+ >>> from kss.pluginregistry import command_set_registry
+
+Now we can register our command set. For more information about the registry
look at the documentation of kss.pluginregistry.
+
+ >>> command_set_registry.register('core', KSSCoreCommands)
+
+To access a command set just need to create our command renderer like we do
+normally.
+
+ >>> commands = KSSCommands()
+
+We can now access the command set.
+
+ >>> core = commands.get_command_set('core')
+
+This command set is initialized and ready for usage.
+
+ >>> core.replace_inner_html(CSS('div'), 'example')
Modified: kukit/kss.commands/trunk/kss/commands/commands.py
==============================================================================
--- kukit/kss.commands/trunk/kss/commands/commands.py (original)
+++ kukit/kss.commands/trunk/kss/commands/commands.py Sun May 13 19:00:42 2007
@@ -1,5 +1,6 @@
from xml.sax.saxutils import escape, quoteattr
from xml.parsers.expat import ParserCreate, ExpatError
+from kss.pluginregistry import command_set_registry
kss_response_header = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:kukit="http://www.kukit.org/commands/1.0"><body><kukit:commands>'''
@@ -45,6 +46,9 @@
output.append(kss_response_footer)
return ''.join(output)
+ def get_command_set(self, name):
+ return command_set_registry.get(name)(self)
+
class KSSCommandSet(object):
def __init__(self, commands):
self.commands = commands
Modified: kukit/kss.commands/trunk/kss/commands/corecommands.py
==============================================================================
--- kukit/kss.commands/trunk/kss/commands/corecommands.py (original)
+++ kukit/kss.commands/trunk/kss/commands/corecommands.py Sun May 13
19:00:42 2007
@@ -1,5 +1,5 @@
from commands import KSSCommandSet
class KSSCoreCommands(KSSCommandSet):
- def replaceInnerHTML(self, selector, value):
+ def replace_inner_html(self, selector, value):
self.commands.add('replaceInnerHTML', selector, html=value)
Modified: kukit/kss.commands/trunk/setup.py
==============================================================================
--- kukit/kss.commands/trunk/setup.py (original)
+++ kukit/kss.commands/trunk/setup.py Sun May 13 19:00:42 2007
@@ -24,9 +24,13 @@
zip_safe=False,
install_requires=[
'setuptools',
+ 'kss.pluginregistry>=dev',
],
entry_points="""
# -*- Entry points: -*-
""",
test_suite='kss.commands.tests.test_suite',
- )
+ dependency_links=[
+
'https://codespeak.net/svn/kukit/kss.pluginregistry/trunk#egg=kss.pluginregistry-dev',
+ ]
+)
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins