Author: jvloothuis
Date: Sun Oct 14 11:17:02 2007
New Revision: 47442

Modified:
   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.py
   kukit/kss.base/trunk/kss/base/corecommands.txt
   kukit/kss.base/trunk/kss/base/coreselectors.py
   kukit/kss.base/trunk/kss/base/plugin.txt
   kukit/kss.base/trunk/kss/base/selectors.txt
Log:

Lower cased the core selectors to match their client side counter
parts.

Removed the lookup method in favour of a __getattr__ lookup.


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 Oct 14 11:17:02 2007
@@ -18,10 +18,10 @@
         self.commands = []
 
     def add(self, action, selector, **kwargs):
-        self.strip_none_parameters(kwargs)
+        self._strip_none_parameters(kwargs)
         self.commands.append((action, selector, kwargs))
 
-    def strip_none_parameters(self, parameters):
+    def _strip_none_parameters(self, parameters):
         for key, value in parameters.items():
             if value is None:
                 del parameters[key]
@@ -40,9 +40,6 @@
         output.append(kss_response_footer)
         return ''.join(output)
 
-    def lookup(self, name):
-        return command_set_registry.get(name)(self)
-
     def clear(self):
         self.commands = []
 
@@ -61,6 +58,9 @@
                     'options': format_options(options)})
         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/kss/base/commands.txt
==============================================================================
--- kukit/kss.base/trunk/kss/base/commands.txt  (original)
+++ kukit/kss.base/trunk/kss/base/commands.txt  Sun Oct 14 11:17:02 2007
@@ -21,8 +21,8 @@
 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
-  >>> commands.add('replaceHTML', CSS('#someid'), html='some value')
+  >>> from kss.base.coreselectors 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
 which will be invoked on the client. Our second argument is the selector.
@@ -31,7 +31,7 @@
 You can add any number of commands this way. Each command will be executed
 in the order that it is added.
 
-  >>> commands.add('someOtherAction', CSS('#otherid'), arg='some arg')
+  >>> commands.add('someOtherAction', css('#otherid'), arg='some arg')
 
 Now that we have a few commands we can render them.
 
@@ -50,7 +50,7 @@
 
 It becomes more interesting if we add a command.
 
-  >>> commands.add('replaceHTML', CSS('#someid'))
+  >>> commands.add('replaceHTML', css('#someid'))
   >>> print commands
   replaceHTML(css('#someid'))
 
@@ -59,13 +59,13 @@
 stable for testing.
 
   >>> commands = KSSCommands()
-  >>> commands.add('replaceHTML', CSS('#someid'), b_arg='some data', 
a_arg='cheese')
+  >>> commands.add('replaceHTML', css('#someid'), b_arg='some data', 
a_arg='cheese')
   >>> print commands
   replaceHTML(css('#someid'), a_arg='cheese', b_arg='some data')
 
 Multiple commands are put on seperate lines.
 
-  >>> commands.add('otherCommand', CSS('#something'))
+  >>> commands.add('otherCommand', css('#something'))
   >>> print commands
   replaceHTML(css('#someid'), a_arg='cheese', b_arg='some data')
   otherCommand(css('#something'))
@@ -74,7 +74,7 @@
 response.
 
   >>> commands.clear()
-  >>> commands.add('parameterCommand', CSS('#something'),
+  >>> commands.add('parameterCommand', css('#something'),
   ...              value='Testing', other_value=None)
   >>> print commands
   parameterCommand(css('#something'), value='Testing')
@@ -125,13 +125,10 @@
 
   >>> commands = KSSCommands()
 
-We can now access the command set.
-
-  >>> core = commands.lookup('core')
-
-This command set is initialized and ready for usage.
-
-  >>> core.replaceInnerHTML(CSS('div'), 'example')
-
+We can now access the command set. This is done using attribute access.
 
+  >>> commands.core.replaceInnerHTML(css('div'), 'example')
+  >>> print commands
+  replaceInnerHTML(css('div'), html='example')
+  
   >>> command_set_registry.unregister('core')
\ No newline at end of file

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 Oct 14 11:17:02 2007
@@ -2,7 +2,7 @@
 
 from kss.base.plugin import Plugin, javascripts_from
 from kss.base.corecommands import KSSCoreCommands
-from kss.base.coreselectors import CSS, HTMLId, SameNode, ParentNode
+from kss.base.coreselectors import css, htmlid, samenode, parentnode
 
 kukit_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'kukit')
 
@@ -40,5 +40,5 @@
         'core': KSSCoreCommands,
         }
 
-    selectors = [CSS, HTMLId, SameNode, ParentNode]
+    selectors = [css, htmlid, samenode, parentnode]
 

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       Sun Oct 14 11:17:02 2007
@@ -1,5 +1,20 @@
 from kss.base.commands import KSSCommandSet
 
+from kss.base.selectors import Selector
+from kss.base.coreselectors import css
+
+class default_selector_type(object):
+    def __init__(self, default):
+        self.default = default
+
+    def __call__(self, func):
+        default = self.default
+        def action(self, selector, *args, **kwargs):
+            if not isinstance(selector, Selector):
+                selector = default(selector)
+            return func(self, selector, *args, **kwargs)
+        return action
+
 class KSSCoreCommands(KSSCommandSet):
 
     def setAttribute(self, selector, name, value):
@@ -23,7 +38,7 @@
         self.commands.add('focus', selector)
 
 
-
+    @default_selector_type(css)
     def replaceInnerHTML(self, selector, value):
         """Replace the contents of a node (selector) with the new `value`"""
         self.commands.add('replaceInnerHTML', selector, html=value)

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 Oct 14 11:17:02 2007
@@ -9,14 +9,14 @@
 
   >>> from kss.base.corecommands import KSSCoreCommands
   >>> from kss.base import KSSCommands
-  >>> from kss.base.coreselectors import CSS
+  >>> 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>')
+  >>> core.replaceInnerHTML(css('div'), 'some <h1>html</h1>')
   >>> commands.render()
   '...replaceInnerHTML...some <h1>html</h1>...'
 
@@ -28,7 +28,7 @@
 -------------
 
   >>> commands.clear()
-  >>> core.setAttribute(CSS('div'), 'some name', 'some value')
+  >>> core.setAttribute(css('div'), 'some name', 'some value')
   >>> print commands
   setAttribute(css('div'), name='some name', value='some value')
 
@@ -36,7 +36,7 @@
 ---------
 
   >>> commands.clear()
-  >>> core.setStyle(CSS('div'), 'somename', 'some value')
+  >>> core.setStyle(css('div'), 'somename', 'some value')
   >>> print commands
   setStyle(css('div'), name='somename', value='some value')
 
@@ -44,7 +44,7 @@
 ---------
 
   >>> commands.clear()
-  >>> core.addClass(CSS('div'), 'somename')
+  >>> core.addClass(css('div'), 'somename')
   >>> print commands
   addClass(css('div'), value='somename')
 
@@ -53,7 +53,7 @@
 ------------
 
   >>> commands.clear()
-  >>> core.removeClass(CSS('div'), 'somename')
+  >>> core.removeClass(css('div'), 'somename')
   >>> print commands
   removeClass(css('div'), value='somename')
 
@@ -61,7 +61,7 @@
 ------------
 
   >>> commands.clear()
-  >>> core.toggleClass(CSS('div'), 'somename')
+  >>> core.toggleClass(css('div'), 'somename')
   >>> print commands
   toggleClass(css('div'), value='somename')
 
@@ -70,7 +70,7 @@
 -----
 
   >>> commands.clear()
-  >>> core.focus(CSS('div'))
+  >>> core.focus(css('div'))
   >>> print commands
   focus(css('div'))
 
@@ -82,7 +82,7 @@
 ------------------
 
   >>> commands.clear()
-  >>> core.replaceInnerHTML(CSS('div'), 'some html')
+  >>> core.replaceInnerHTML(css('div'), 'some html')
   >>> print commands
   replaceInnerHTML(css('div'), html='some html')
 
@@ -90,7 +90,7 @@
 ------------
 
   >>> commands.clear()
-  >>> core.replaceHTML(CSS('div'), 'some html')
+  >>> core.replaceHTML(css('div'), 'some html')
   >>> print commands
   replaceHTML(css('div'), html='some html')
 
@@ -103,7 +103,7 @@
 ------------------
 
   >>> commands.clear()
-  >>> core.insertHTMLBefore(CSS('div'), 'some html')
+  >>> core.insertHTMLBefore(css('div'), 'some html')
   >>> print commands
   insertHTMLBefore(css('div'), html='some html')
 
@@ -111,7 +111,7 @@
 -----------------
 
   >>> commands.clear()
-  >>> core.insertHTMLAfter(CSS('div'), 'some html')
+  >>> core.insertHTMLAfter(css('div'), 'some html')
   >>> print commands
   insertHTMLAfter(css('div'), html='some html')
 
@@ -119,7 +119,7 @@
 --------------------------
 
   >>> commands.clear()
-  >>> core.insertHTMLAsFirstChild(CSS('div'), 'some html')
+  >>> core.insertHTMLAsFirstChild(css('div'), 'some html')
   >>> print commands
   insertHTMLAsFirstChild(css('div'), html='some html')
 
@@ -127,7 +127,7 @@
 --------------------------
 
   >>> commands.clear()
-  >>> core.insertHTMLAsLastChild(CSS('div'), 'some html')
+  >>> core.insertHTMLAsLastChild(css('div'), 'some html')
   >>> print commands
   insertHTMLAsLastChild(css('div'), html='some html')
 
@@ -140,7 +140,7 @@
 -----------
 
   >>> commands.clear()
-  >>> core.deleteNode(CSS('div'))
+  >>> core.deleteNode(css('div'))
   >>> print commands
   deleteNode(css('div'))
 
@@ -148,7 +148,7 @@
 ------------------
 
   >>> commands.clear()
-  >>> core.deleteNodeBefore(CSS('div'))
+  >>> core.deleteNodeBefore(css('div'))
   >>> print commands
   deleteNodeBefore(css('div'))
 
@@ -156,7 +156,7 @@
 -----------------
 
   >>> commands.clear()
-  >>> core.deleteNodeAfter(CSS('div'))
+  >>> core.deleteNodeAfter(css('div'))
   >>> print commands
   deleteNodeAfter(css('div'))
 
@@ -164,7 +164,7 @@
 -----------------
 
   >>> commands.clear()
-  >>> core.focus(CSS('div'))
+  >>> core.focus(css('div'))
   >>> print commands
   focus(css('div'))
 
@@ -177,7 +177,7 @@
 ----------------------
 
   >>> commands.clear()
-  >>> core.copyChildNodesFrom(CSS('div'), 'nodeid')
+  >>> core.copyChildNodesFrom(css('div'), 'nodeid')
   >>> print commands
   copyChildNodesFrom(css('div'), html_id='nodeid')
 
@@ -186,7 +186,7 @@
 -------------------
 
   >>> commands.clear()
-  >>> core.copyChildNodesTo(CSS('div'), 'nodeid')
+  >>> core.copyChildNodesTo(css('div'), 'nodeid')
   >>> print commands
   copyChildNodesTo(css('div'), html_id='nodeid')
 
@@ -199,7 +199,7 @@
 ----------------
 
   >>> commands.clear()
-  >>> core.moveNodeBefore(CSS('div'), 'nodeid')
+  >>> core.moveNodeBefore(css('div'), 'nodeid')
   >>> print commands
   moveNodeBefore(css('div'), html_id='nodeid')
 
@@ -207,6 +207,6 @@
 ---------------
 
   >>> commands.clear()
-  >>> core.moveNodeAfter(CSS('div'), 'nodeid')
+  >>> core.moveNodeAfter(css('div'), 'nodeid')
   >>> print commands
   moveNodeAfter(css('div'), html_id='nodeid')

Modified: kukit/kss.base/trunk/kss/base/coreselectors.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/coreselectors.py      (original)
+++ kukit/kss.base/trunk/kss/base/coreselectors.py      Sun Oct 14 11:17:02 2007
@@ -1,17 +1,17 @@
 from kss.base.selectors import Selector
 
-class CSS(Selector):
+class css(Selector):
     def __init__(self, value):
-        super(CSS, self).__init__('css', value)
+        super(css, self).__init__('css', value)
 
-class HTMLId(Selector):
+class htmlid(Selector):
     def __init__(self, value):
-        super(HTMLId, self).__init__('htmlid', value)
+        super(htmlid, self).__init__('htmlid', value)
 
-class SameNode(Selector):
+class samenode(Selector):
     def __init__(self):
-        super(SameNode, self).__init__('samenode', '')
+        super(samenode, self).__init__('samenode', '')
 
-class ParentNode(Selector):
+class parentnode(Selector):
     def __init__(self, value):
-        super(ParentNode, self).__init__('parentnode', value)
+        super(parentnode, self).__init__('parentnode', value)

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 Oct 14 11:17:02 2007
@@ -26,7 +26,7 @@
 
   >>> import kss.base
   >>> from kss.base.corecommands import KSSCoreCommands
-  >>> from kss.base.coreselectors import CSS
+  >>> from kss.base.coreselectors import css
 
   >>> class ExamplePlugin(Plugin):
   ...     javascripts = [file_below_module(kss.base,
@@ -35,7 +35,7 @@
   ...     commandsets = {
   ...         'example': KSSCoreCommands,
   ...         }
-  ...     selectors = [CSS]
+  ...     selectors = [css]
 
 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

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 Oct 14 11:17:02 2007
@@ -1,9 +1,6 @@
 Selectors
 =========
 
-!TODO: Make selectors pluggable. Do this by importing entry_points
- into the kss.base.selectors namespace
-
 The selector is responsible for finding the nodes on which to operate.
 Selectors are executed on the client. They need a name and an optional
 parameter.
@@ -27,17 +24,17 @@
 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.coreselectors import css, htmlid
 
 They both need a value to operate on.
 
-  >>> selector = CSS('div.main a')
+  >>> selector = css('div.main a')
   >>> selector.type
   'css'
   >>> selector.value
   'div.main a'
 
-  >>> selector = HTMLId('someid')
+  >>> selector = htmlid('someid')
   >>> selector.type
   'htmlid'
   >>> selector.value
@@ -47,8 +44,8 @@
 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
-  >>> selector = SameNode()
+  >>> from kss.base.coreselectors import samenode
+  >>> selector = samenode()
   >>> selector.type
   'samenode'
   >>> selector.value
@@ -58,8 +55,8 @@
 query which only operates on nodes that are the parent (or
 grandparents).
 
-  >>> from kss.base.coreselectors import ParentNode
-  >>> selector = ParentNode('a')
+  >>> from kss.base.coreselectors import parentnode
+  >>> selector = parentnode('a')
   >>> selector.type
   'parentnode'
   >>> selector.value
@@ -75,5 +72,5 @@
   >>> print Selector('type', 'value')
   type('value')
 
-  >>> print CSS('div.content')
+  >>> print css('div.content')
   css('div.content')
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to