Author: jvloothuis
Date: Wed Jul 2 20:50:30 2008
New Revision: 56248
Added:
kukit/kss.base/trunk/src/kss/base/core.py
- copied unchanged from r56247,
kukit/kss.base/branches/grokkerdam-api-tweaks/src/kss/base/core.py
kukit/kss.base/trunk/src/kss/base/core.txt
- copied unchanged from r56247,
kukit/kss.base/branches/grokkerdam-api-tweaks/src/kss/base/core.txt
Removed:
kukit/kss.base/trunk/src/kss/base/commandset.py
kukit/kss.base/trunk/src/kss/base/corecommands.py
kukit/kss.base/trunk/src/kss/base/corecommands.txt
Modified:
kukit/kss.base/trunk/docs/HISTORY.txt
kukit/kss.base/trunk/src/kss/base/__init__.py
kukit/kss.base/trunk/src/kss/base/commands.py
kukit/kss.base/trunk/src/kss/base/commands.txt
kukit/kss.base/trunk/src/kss/base/config.py
kukit/kss.base/trunk/src/kss/base/plugin.py
kukit/kss.base/trunk/src/kss/base/plugin.txt
kukit/kss.base/trunk/src/kss/base/registry.py
kukit/kss.base/trunk/src/kss/base/selectors.py
kukit/kss.base/trunk/src/kss/base/tests.py
Log:
Merged with the branch made on the Grokkerdam sprint based on Balazs's
feedback. The shorty summary is that concept of command sets changed
from classes to modules.
Modified: kukit/kss.base/trunk/docs/HISTORY.txt
==============================================================================
--- kukit/kss.base/trunk/docs/HISTORY.txt (original)
+++ kukit/kss.base/trunk/docs/HISTORY.txt Wed Jul 2 20:50:30 2008
@@ -4,6 +4,15 @@
kss.base - 0.4dev Unreleased
+ - changed the concept of command sets from classes to
+ modules. This means you now need to import the helpers
+ directly. For the core this would mean doing something like
+ this::
+
+ from kss.base import core, KSSCommands
+ commands = KSSCommands()
+ core.replaceInnerHTML(commands, '#some-node', 'some value')
+
- renamed `load_plugins`, `unload_plugins`, and `activated_plugins`
to respectively `activate`, `deactivate`, and `active_plugins`
[gotcha]
Modified: kukit/kss.base/trunk/src/kss/base/__init__.py
==============================================================================
--- kukit/kss.base/trunk/src/kss/base/__init__.py (original)
+++ kukit/kss.base/trunk/src/kss/base/__init__.py Wed Jul 2 20:50:30 2008
@@ -1,4 +1,3 @@
from kss.base.commands import KSSCommands
-from kss.base.selectors import selectors
from kss.base.plugin import activate
from kss.base.commands import xmldata, htmldata, cdatadata
Modified: kukit/kss.base/trunk/src/kss/base/commands.py
==============================================================================
--- kukit/kss.base/trunk/src/kss/base/commands.py (original)
+++ kukit/kss.base/trunk/src/kss/base/commands.py Wed Jul 2 20:50:30 2008
@@ -6,7 +6,6 @@
except ImportError: # no soup support
BeautifulSoup = BeautifulStoneSoup = lambda v: v
-from kss.base.registry import command_set_registry
from kss.base.selectors import Selector
soup_enabled = False
@@ -122,9 +121,3 @@
lines.append(line + ')')
return '\n'.join(lines)
- def __getattr__(self, name):
- return command_set_registry.get(name)(self)
-
-class KSSCommandSet(object):
- def __init__(self, commands):
- self.commands = commands
Modified: kukit/kss.base/trunk/src/kss/base/commands.txt
==============================================================================
--- kukit/kss.base/trunk/src/kss/base/commands.txt (original)
+++ kukit/kss.base/trunk/src/kss/base/commands.txt Wed Jul 2 20:50:30 2008
@@ -172,61 +172,6 @@
replaceHTML('#someid', html='some value')
-Command sets
-============
-
-Command sets wrap the commands system and provide a highlevel API to
-communicate with the browser. Command sets are responsible for escaping and
-validating data.
-
-Let us take a look at the base class for all commandsets.
-
- >>> from kss.base.commands import KSSCommandSet
- >>> commands = KSSCommands()
- >>> commandset = KSSCommandSet(commands)
-
-It wraps commands in the command set. We can still access the
-commands directly by using the `commands` attribute.
-
- >>> commandset.commands
- <...KSSCommands object at ...>
-
-Take a look at the core command set for a better understanding of the usage
pattern.
-
-
-Using command sets
-==================
-
-In the previous examples, we saw how to load command sets directly. Usually, 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.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.)
-
- >>> command_set_registry.register('core', KSSCoreCommands)
-
-Command sets are accessed as attributes on the command renderer.
-
- >>> commands = KSSCommands()
- >>> commands.core.replaceInnerHTML(css('div'), 'example')
- >>> print commands
- replaceInnerHTML(css('div'), html=htmldata('example'))
-
-In this case, we used `replaceInnerHTML` method that is defined in the core
-command set. This is equivalent but shorter than explicitely adding a command.
-
-Let us clean up.
-
- >>> command_set_registry.unregister('core')
-
-
Soup support
============
Deleted: /kukit/kss.base/trunk/src/kss/base/commandset.py
==============================================================================
Modified: kukit/kss.base/trunk/src/kss/base/config.py
==============================================================================
--- kukit/kss.base/trunk/src/kss/base/config.py (original)
+++ kukit/kss.base/trunk/src/kss/base/config.py Wed Jul 2 20:50:30 2008
@@ -1,7 +1,7 @@
import os
from kss.base.plugin import Plugin
-from kss.base.corecommands import KSSCoreCommands
+from kss.base import core
from kss.base.selectors import css, htmlid, samenode, parentnode
kukit_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'kukit')
@@ -43,7 +43,7 @@
for f in third_party_js]
commandsets = {
- 'core': KSSCoreCommands,
+ 'core': core,
}
selectors = {None: [css, htmlid, samenode, parentnode]}
Deleted: /kukit/kss.base/trunk/src/kss/base/corecommands.py
==============================================================================
--- /kukit/kss.base/trunk/src/kss/base/corecommands.py Wed Jul 2 20:50:30 2008
+++ (empty file)
@@ -1,91 +0,0 @@
-from kss.base.commands import KSSCommandSet
-from kss.base import htmldata
-
-class KSSCoreCommands(KSSCommandSet):
-
- 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 properties cannot contain spaces')
- self.commands.add('setStyle', selector, name=name, value=value)
-
- def addClass(self, selector, value):
- self.commands.add('addClass', selector, value=value)
-
- def removeClass(self, selector, value):
- self.commands.add('removeClass', selector, value=value)
-
- def toggleClass(self, selector, value):
- self.commands.add('toggleClass', selector, value=value)
-
- def focus(self, selector):
- self.commands.add('focus', selector)
-
- def replaceInnerHTML(self, selector, value, withKssSetup=True):
- """Replace the contents of a node (selector) with the new `value`"""
- extra_args = {}
- if not withKssSetup:
- extra_args['withKssSetup'] = 'False'
- self.commands.add('replaceInnerHTML', selector, html=htmldata(value),
- **extra_args)
-
- def replaceHTML(self, selector, value, withKssSetup=True):
- extra_args = {}
- if not withKssSetup:
- extra_args['withKssSetup'] = 'False'
- self.commands.add('replaceHTML', selector, html=value,
- **extra_args)
-
- def insertHTMLBefore(self, selector, value):
- self.commands.add('insertHTMLBefore', selector, html=value)
-
- def insertHTMLAfter(self, selector, value):
- self.commands.add('insertHTMLAfter', selector, html=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 deleteNode(self, selector):
- self.commands.add('deleteNode', selector)
-
- def deleteNodeBefore(self, selector):
- self.commands.add('deleteNodeBefore', selector)
-
- def deleteNodeAfter(self, selector):
- self.commands.add('deleteNodeAfter', selector)
-
- def clearChildNodes(self, selector):
- self.commands.add('clearChildNodes', selector)
-
-
-
- def copyChildNodesFrom(self, selector, id):
- self.commands.add('copyChildNodesFrom', selector, html_id=id)
-
- def copyChildNodesTo(self, selector, id):
- self.commands.add('copyChildNodesTo', selector, html_id=id)
-
-
-
- def moveNodeBefore(self, selector, id):
- self.commands.add('moveNodeBefore', selector, html_id=id)
-
- def moveNodeAfter(self, selector, id):
- self.commands.add('moveNodeAfter', selector, html_id=id)
-
-
- def setStateVar(self, varname, value):
- self.commands.add('setStateVar', None, varname=varname, value=value)
-
- def triggerEvent(self, name, **kwargs):
- self.commands.add('triggerEvent', None, name=name, **kwargs)
-
-
-
Deleted: /kukit/kss.base/trunk/src/kss/base/corecommands.txt
==============================================================================
--- /kukit/kss.base/trunk/src/kss/base/corecommands.txt Wed Jul 2 20:50:30 2008
+++ (empty file)
@@ -1,265 +0,0 @@
-=============
-Core commands
-=============
-
-The core commands wrap all KSS commands provided by the core plugin.
-They are always available.
-These do not contain any effects and focus mostly on DOM manipulation.
-
-First we instantiate the command set.
-
- >>> from kss.base.corecommands import KSSCoreCommands
- >>> from kss.base import KSSCommands
- >>> from kss.base.selectors import css
-
- >>> commands = KSSCommands()
- >>> core = KSSCoreCommands(commands)
-
-Let us look at the individual methods provided by the core commands.
-
- >>> core.replaceInnerHTML(css('div'), 'some <h1>html</h1>')
- >>> commands.render()
- '...replaceInnerHTML...<![CDATA[some <h1>html</h1>]]>...'
-
------------------
-Node modification
------------------
-
-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
----------
-
-You can use `setStyle` to change the look off an element.
-
- >>> commands.clear()
- >>> core.setStyle(css('div'), 'somename', 'some value')
- >>> print commands
- setStyle(css('div'), name='somename', value='some value')
-
-It also has some validation so that you do not accidentily do an
-unallowed thing.
-
- >>> core.setStyle(css('div'), 'some name', 'some value')
- Traceback (most recent call last):
- ...
- ValueError: Style properties cannot contain spaces
-
-
-Add class
----------
-
- >>> commands.clear()
- >>> core.addClass(css('div'), 'somename')
- >>> print commands
- addClass(css('div'), value='somename')
-
-
-Remove class
-------------
-
- >>> commands.clear()
- >>> core.removeClass(css('div'), 'somename')
- >>> print commands
- removeClass(css('div'), value='somename')
-
-Toggle class
-------------
-
- >>> commands.clear()
- >>> core.toggleClass(css('div'), 'somename')
- >>> print commands
- toggleClass(css('div'), value='somename')
-
-
-----------------
-HTML replacement
-----------------
-
-Replace inner HTML
-------------------
-
- >>> commands.clear()
- >>> core.replaceInnerHTML(css('div'), 'some html')
- >>> print commands
- replaceInnerHTML(css('div'), html=htmldata('some html'))
-
-You can also avoid KSS event setup. Use this only if you really need
-the speedup, as the KSS resource will not be bound to those new nodes.
-
- >>> core.replaceInnerHTML(css('div'), 'some html', withKssSetup=False)
- >>> print commands
- replaceInnerHTML(css('div'), html=htmldata('some html'))
- replaceInnerHTML(css('div'), html=htmldata('some html'),
withKssSetup='False')
-
-
-Replace HTML
-------------
-
- >>> commands.clear()
- >>> core.replaceHTML(css('div'), 'some html')
- >>> print commands
- replaceHTML(css('div'), html='some html')
-
-You can also pass withKssSetup here (see replace inner HTML).
-
- >>> core.replaceHTML(css('div'), 'some html', withKssSetup=False)
- >>> print commands
- replaceHTML(css('div'), html='some html')
- replaceHTML(css('div'), html='some html', withKssSetup='False')
-
-
---------------
-HTML insertion
---------------
-
-Insert HTML before
-------------------
-
- >>> commands.clear()
- >>> core.insertHTMLBefore(css('div'), 'some html')
- >>> print commands
- insertHTMLBefore(css('div'), html='some html')
-
-Insert HTML after
------------------
-
- >>> commands.clear()
- >>> core.insertHTMLAfter(css('div'), 'some html')
- >>> print commands
- insertHTMLAfter(css('div'), html='some html')
-
-Insert HTML as first child
---------------------------
-
- >>> commands.clear()
- >>> core.insertHTMLAsFirstChild(css('div'), 'some html')
- >>> print commands
- insertHTMLAsFirstChild(css('div'), html='some html')
-
-Insert HTML as last child
---------------------------
-
- >>> commands.clear()
- >>> core.insertHTMLAsLastChild(css('div'), 'some html')
- >>> print commands
- insertHTMLAsLastChild(css('div'), html='some html')
-
-
-------------
-Node removal
-------------
-
-Delete node
------------
-
- >>> commands.clear()
- >>> core.deleteNode(css('div'))
- >>> print commands
- deleteNode(css('div'))
-
-Delete node before
-------------------
-
- >>> commands.clear()
- >>> core.deleteNodeBefore(css('div'))
- >>> print commands
- deleteNodeBefore(css('div'))
-
-Delete node after
------------------
-
- >>> commands.clear()
- >>> core.deleteNodeAfter(css('div'))
- >>> print commands
- deleteNodeAfter(css('div'))
-
-Clear child nodes
------------------
-
- >>> commands.clear()
- >>> core.clearChildNodes(css('div'))
- >>> print commands
- clearChildNodes(css('div'))
-
--------
-Special
--------
-
-Focus
------
-
- >>> commands.clear()
- >>> core.focus(css('div'))
- >>> print commands
- focus(css('div'))
-
-
--------------
-Copying nodes
--------------
-
-Copy child nodes from
-----------------------
-
- >>> commands.clear()
- >>> core.copyChildNodesFrom(css('div'), 'nodeid')
- >>> print commands
- copyChildNodesFrom(css('div'), html_id='nodeid')
-
-
-Copy child nodes to
--------------------
-
- >>> commands.clear()
- >>> core.copyChildNodesTo(css('div'), 'nodeid')
- >>> print commands
- copyChildNodesTo(css('div'), html_id='nodeid')
-
-
-------------
-Moving nodes
-------------
-
-Move node before
-----------------
-
- >>> commands.clear()
- >>> core.moveNodeBefore(css('div'), 'nodeid')
- >>> print commands
- moveNodeBefore(css('div'), html_id='nodeid')
-
-Move node after
----------------
-
- >>> commands.clear()
- >>> core.moveNodeAfter(css('div'), 'nodeid')
- >>> print commands
- moveNodeAfter(css('div'), html_id='nodeid')
-
-
---------------
-Global actions
---------------
-
-Set client variable
--------------------
-
- >>> commands.clear()
- >>> core.setStateVar('varname', 'value')
- >>> print commands
- setStateVar(varname='varname', value='value')
-
-Trigger event
--------------
-
- >>> commands.clear()
- >>> core.triggerEvent('eventname')
- >>> print commands
- triggerEvent(name='eventname')
Modified: kukit/kss.base/trunk/src/kss/base/plugin.py
==============================================================================
--- kukit/kss.base/trunk/src/kss/base/plugin.py (original)
+++ kukit/kss.base/trunk/src/kss/base/plugin.py Wed Jul 2 20:50:30 2008
@@ -2,8 +2,7 @@
from pkg_resources import iter_entry_points
-from kss.base.registry import command_set_registry, plugin_registry
-from kss.base import selectors as selector_registry
+from kss.base.registry import plugin_registry
class Plugin(object):
priority = 100
@@ -13,28 +12,6 @@
selectors = {}
commandsets = {}
- def register_commandsets(self, registry):
- for name, commandset in self.commandsets.iteritems():
- registry.register(name, commandset)
-
- def unregister_commandsets(self, registry):
- for name, commandset in self.commandsets.iteritems():
- registry.unregister(name)
-
- def _selectors(self):
- for name, selectors in self.selectors.iteritems():
- for selector in selectors:
- yield selector.type, selector
-
- def register_selectors(self):
- for id, selector in self._selectors():
- selector_registry.register(id, selector)
-
- def unregister_selectors(self):
- for id, selector in self._selectors():
- selector_registry.unregister(id)
-
-
def javascripts_from(path):
javascripts = []
if not os.path.isdir(path):
@@ -70,9 +47,6 @@
plugin = plugin_factory()
plugin_registry.register(name, plugin)
- # Setup of all hooks
- plugin.register_commandsets(command_set_registry)
- plugin.register_selectors()
return
raise KeyError("Plugin is not registered: %s" % name)
@@ -85,10 +59,6 @@
plugin_factory = entry_point.load()
plugin = plugin_factory()
- # Tear down of all hooks
- plugin.unregister_commandsets(command_set_registry)
- plugin.unregister_selectors()
-
plugin_registry.unregister(name)
Modified: kukit/kss.base/trunk/src/kss/base/plugin.txt
==============================================================================
--- kukit/kss.base/trunk/src/kss/base/plugin.txt (original)
+++ kukit/kss.base/trunk/src/kss/base/plugin.txt Wed Jul 2 20:50:30 2008
@@ -26,7 +26,7 @@
example.)
>>> import kss.base
- >>> from kss.base.corecommands import KSSCoreCommands
+ >>> from kss.base import core
>>> from kss.base.selectors import Selector
>>> class Silly(Selector):
@@ -40,7 +40,7 @@
... 'javascript/plugin.js')]
... extra_javascripts = []
... commandsets = {
- ... 'example': KSSCoreCommands,
+ ... 'example': core,
... }
... selectors = {'example': [Silly]}
@@ -87,14 +87,6 @@
>>> tuple(active_plugins())
(('kss-testing', <ExamplePlugin object at ...>),)
-The additional selector we registered is now available in the selector
-registry. It can be looked up based on the class name with the key
-from the registrion as the namespace.
-
- >>> from kss.base import selectors
- >>> print selectors['example-silly']('testing')
- example-silly('testing')
-
Finally we deactivate our plugin to clean up.
>>> from kss.base.plugin import deactivate
Modified: kukit/kss.base/trunk/src/kss/base/registry.py
==============================================================================
--- kukit/kss.base/trunk/src/kss/base/registry.py (original)
+++ kukit/kss.base/trunk/src/kss/base/registry.py Wed Jul 2 20:50:30 2008
@@ -18,5 +18,4 @@
__getitem__ = get
-command_set_registry = Registry()
plugin_registry = Registry()
Modified: kukit/kss.base/trunk/src/kss/base/selectors.py
==============================================================================
--- kukit/kss.base/trunk/src/kss/base/selectors.py (original)
+++ kukit/kss.base/trunk/src/kss/base/selectors.py Wed Jul 2 20:50:30 2008
@@ -1,5 +1,3 @@
-from kss.base.registry import Registry
-
class Selector(object):
"""A base for selectors. Plugins that implement this, need
to implement __init__ themselves, and set type as a string.
@@ -40,5 +38,3 @@
def __init__(self, value):
self.value = value
-
-selectors = Registry()
Modified: kukit/kss.base/trunk/src/kss/base/tests.py
==============================================================================
--- kukit/kss.base/trunk/src/kss/base/tests.py (original)
+++ kukit/kss.base/trunk/src/kss/base/tests.py Wed Jul 2 20:50:30 2008
@@ -6,7 +6,7 @@
doctest.DocFileSuite(
'selectors.txt',
'registry.txt', 'plugin.txt',
- 'commands.txt', 'corecommands.txt',
+ 'commands.txt', 'core.txt',
'javascript.txt', 'utils.txt',
package='kss.base',
optionflags=doctest.ELLIPSIS|doctest.REPORT_ONLY_FIRST_FAILURE,
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins