Author: jvloothuis Date: Sun Dec 2 13:41:57 2007 New Revision: 49275 Removed: kukit/kss.base/trunk/kss/base/coreselectors.py Modified: kukit/kss.base/trunk/kss/base/__init__.py kukit/kss.base/trunk/kss/base/commands.py kukit/kss.base/trunk/kss/base/commands.txt kukit/kss.base/trunk/kss/base/config.py kukit/kss.base/trunk/kss/base/corecommands.txt kukit/kss.base/trunk/kss/base/plugin.py kukit/kss.base/trunk/kss/base/plugin.txt kukit/kss.base/trunk/kss/base/registry.py kukit/kss.base/trunk/kss/base/selectors.py kukit/kss.base/trunk/kss/base/selectors.txt Log:
Changed the selector registration so that it now supports namespaces for selectors. It still has the shortcuts for the core selectors so this change only affects plugin writers. Modified: kukit/kss.base/trunk/kss/base/__init__.py ============================================================================== --- kukit/kss.base/trunk/kss/base/__init__.py (original) +++ kukit/kss.base/trunk/kss/base/__init__.py Sun Dec 2 13:41:57 2007 @@ -1,2 +1,3 @@ from kss.base.commands import KSSCommands +from kss.base.selectors import selectors from kss.base.plugin import load_plugins 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 Sun Dec 2 13:41:57 2007 @@ -1,7 +1,7 @@ from xml.sax.saxutils import quoteattr from kss.base.registry import command_set_registry from kss.base.selectors import Selector -from kss.base.coreselectors import css +from kss.base.selectors import css kss_response_header = '''<?xml version="1.0" ?> <kukit xmlns="http://www.kukit.org/commands/1.0"><commands> Modified: kukit/kss.base/trunk/kss/base/commands.txt ============================================================================== --- kukit/kss.base/trunk/kss/base/commands.txt (original) +++ kukit/kss.base/trunk/kss/base/commands.txt Sun Dec 2 13:41:57 2007 @@ -22,7 +22,7 @@ also need to create a selector. In this case we will use the CSS selector. For more information about selectors look at the selector documentation. - >>> from kss.base.coreselectors import css + >>> from kss.base.selectors import css >>> commands.add('replaceHTML', css('#someid'), html='some value') Now we have added a command. The first argument is the name of the action Modified: kukit/kss.base/trunk/kss/base/config.py ============================================================================== --- kukit/kss.base/trunk/kss/base/config.py (original) +++ kukit/kss.base/trunk/kss/base/config.py Sun Dec 2 13:41:57 2007 @@ -2,7 +2,7 @@ from kss.base.plugin import Plugin from kss.base.corecommands import KSSCoreCommands -from kss.base.coreselectors import css, htmlid, samenode, parentnode +from kss.base.selectors import css, htmlid, samenode, parentnode kukit_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'kukit') @@ -46,5 +46,5 @@ 'core': KSSCoreCommands, } - selectors = [css, htmlid, samenode, parentnode] + selectors = {None: [css, htmlid, samenode, parentnode]} Modified: kukit/kss.base/trunk/kss/base/corecommands.txt ============================================================================== --- kukit/kss.base/trunk/kss/base/corecommands.txt (original) +++ kukit/kss.base/trunk/kss/base/corecommands.txt Sun Dec 2 13:41:57 2007 @@ -9,7 +9,7 @@ >>> from kss.base.corecommands import KSSCoreCommands >>> from kss.base import KSSCommands - >>> from kss.base.coreselectors import css + >>> from kss.base.selectors import css >>> commands = KSSCommands() >>> core = KSSCoreCommands(commands) Deleted: /kukit/kss.base/trunk/kss/base/coreselectors.py ============================================================================== --- /kukit/kss.base/trunk/kss/base/coreselectors.py Sun Dec 2 13:41:57 2007 +++ (empty file) @@ -1,17 +0,0 @@ -from kss.base.selectors import Selector - -class css(Selector): - def __init__(self, value): - super(css, self).__init__('css', value) - -class htmlid(Selector): - def __init__(self, value): - super(htmlid, self).__init__('htmlid', value) - -class samenode(Selector): - def __init__(self): - super(samenode, self).__init__('samenode', '') - -class parentnode(Selector): - def __init__(self, value): - super(parentnode, self).__init__('parentnode', 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 Sun Dec 2 13:41:57 2007 @@ -3,7 +3,7 @@ from pkg_resources import iter_entry_points from kss.base.registry import command_set_registry, plugin_registry -from kss.base import selectors as kss_selectors +from kss.base import selectors as selector_registry class Plugin(object): priority = 100 @@ -21,13 +21,22 @@ for name, commandset in self.commandsets.iteritems(): registry.unregister(name) + def _selectors(self): + for name, selectors in self.selectors.iteritems(): + for selector in selectors: + if name is None: + selector_id = selector.__name__ + else: + selector_id = name + '-' + selector.__name__ + yield selector_id, selector + def register_selectors(self): - for selector in self.selectors: - setattr(kss_selectors, selector.__name__, selector) + for id, selector in self._selectors(): + selector_registry.register(id, selector) def unregister_selectors(self): - for selector in self.selectors: - delattr(kss_selectors, selector.__name__) + for id, selector in self._selectors(): + selector_registry.unregister(id) def javascripts_from(path): Modified: kukit/kss.base/trunk/kss/base/plugin.txt ============================================================================== --- kukit/kss.base/trunk/kss/base/plugin.txt (original) +++ kukit/kss.base/trunk/kss/base/plugin.txt Sun Dec 2 13:41:57 2007 @@ -26,7 +26,12 @@ >>> import kss.base >>> from kss.base.corecommands import KSSCoreCommands - >>> from kss.base.coreselectors import css + >>> from kss.base.selectors import Selector + + >>> class silly(Selector): + ... def __init__(self, value): + ... super(silly, self).__init__('example-silly', value) + >>> class ExamplePlugin(Plugin): ... javascripts = [file_below_module(kss.base, @@ -35,7 +40,7 @@ ... commandsets = { ... 'example': KSSCoreCommands, ... } - ... selectors = [css] + ... selectors = {'example': [silly]} As you can see from the lines above the registration has a few things in it. The first thing is registering the Javascripts. All items in @@ -47,8 +52,6 @@ identifiers and the command set factory. When using KSS you would normally use this identifier for the lookup of command sets. -We can also register additional selectors. - If we try the activate our plugin now it will not work. >>> kss.base.load_plugins('kss-testing') @@ -84,6 +87,15 @@ >>> tuple(activated_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 will unregister our plugin to clean up. >>> from kss.base.plugin import unload_plugins 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 Sun Dec 2 13:41:57 2007 @@ -16,5 +16,7 @@ def items(self): return self._items.iteritems() + __getitem__ = get + command_set_registry = Registry() plugin_registry = Registry() Modified: kukit/kss.base/trunk/kss/base/selectors.py ============================================================================== --- kukit/kss.base/trunk/kss/base/selectors.py (original) +++ kukit/kss.base/trunk/kss/base/selectors.py Sun Dec 2 13:41:57 2007 @@ -1,3 +1,5 @@ +from kss.base.registry import Registry + class Selector(object): def __init__(self, type, value): self.type = type @@ -5,3 +7,22 @@ def __str__(self): return "%s('%s')" % (self.type, self.value) + +class css(Selector): + def __init__(self, value): + super(css, self).__init__('css', value) + +class htmlid(Selector): + def __init__(self, value): + super(htmlid, self).__init__('htmlid', value) + +class samenode(Selector): + def __init__(self): + super(samenode, self).__init__('samenode', '') + +class parentnode(Selector): + def __init__(self, value): + super(parentnode, self).__init__('parentnode', value) + + +selectors = Registry() Modified: kukit/kss.base/trunk/kss/base/selectors.txt ============================================================================== --- kukit/kss.base/trunk/kss/base/selectors.txt (original) +++ kukit/kss.base/trunk/kss/base/selectors.txt Sun Dec 2 13:41:57 2007 @@ -24,7 +24,7 @@ In the core package you can find a few standard selectors. The most basic selectors are the CSS and HTML id selectors. - >>> from kss.base.coreselectors import css, htmlid + >>> from kss.base.selectors import css, htmlid They both need a value to operate on. @@ -44,7 +44,7 @@ in that it selects the same node that was used to call the server action. Also note that it does not accept any arguments. - >>> from kss.base.coreselectors import samenode + >>> from kss.base.selectors import samenode >>> selector = samenode() >>> selector.type 'samenode' @@ -55,7 +55,7 @@ query which only operates on nodes that are the parent (or grandparents). - >>> from kss.base.coreselectors import parentnode + >>> from kss.base.selectors import parentnode >>> selector = parentnode('a') >>> selector.type 'parentnode' _______________________________________________ Kukit-checkins mailing list [email protected] http://codespeak.net/mailman/listinfo/kukit-checkins
