Author: jvloothuis
Date: Mon Oct 15 09:47:07 2007
New Revision: 47460

Modified:
   kukit/kss.base/trunk/kss/base/commands.py
   kukit/kss.base/trunk/kss/base/config.py
   kukit/kss.base/trunk/kss/base/corecommands.py
   kukit/kss.base/trunk/kss/base/plugin.py
   kukit/kss.base/trunk/kss/base/plugin.txt
   kukit/kss.base/trunk/kss/base/tests.py
Log:

Moved the auto selector converting (pass a string and it will be
converted to a css selector) to the commands so that all commands will
automatically have it.

Removed unneeded import from tests.py (was used for teardown)

Changed the core plugin config so that only the required extra
Javascript is loaded from the 3rd party directory. This should speed
up page loads.

Loading a non existing plugin now raises an exception. This means that
it is easier to tell if you made a type/forgot to install the plugin.


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   Mon Oct 15 09:47:07 2007
@@ -1,5 +1,6 @@
 from xml.sax.saxutils import quoteattr, escape
 from kss.base.registry import command_set_registry
+from kss.base import selectors
 
 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>'''
@@ -19,6 +20,11 @@
 
     def add(self, action, selector, **kwargs):
         self._strip_none_parameters(kwargs)
+
+        if selector is not None and not isinstance(selector,
+                                                   selectors.Selector):
+            selector = selectors.css(selector)
+
         self.commands.append((action, selector, kwargs))
 
     def _strip_none_parameters(self, parameters):

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     Mon Oct 15 09:47:07 2007
@@ -1,11 +1,12 @@
 import os
 
-from kss.base.plugin import Plugin, javascripts_from
+from kss.base.plugin import Plugin
 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')
 
+# Define the Javascripts by hand to ensure the order
 core_js = ['utils.js',
            'errors.js',
            'oper.js',
@@ -26,6 +27,10 @@
            'plugin.js',
            ]
 
+third_party_js = [
+    'base2-dom-fp.js',
+    'sarissa.js',
+]
 
 class KSSCore(Plugin):
     '''The KSS core plugin has all the standard functionality'''
@@ -33,9 +38,10 @@
     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'))
 
+    extra_javascripts = [os.path.join(kukit_dir, '3rd_party', f)
+                         for f in third_party_js]
+                                           
     commandsets = {
         'core': KSSCoreCommands,
         }

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       Mon Oct 15 09:47:07 2007
@@ -1,20 +1,5 @@
 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):
@@ -37,8 +22,6 @@
     def focus(self, selector):
         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/plugin.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/plugin.py     (original)
+++ kukit/kss.base/trunk/kss/base/plugin.py     Mon Oct 15 09:47:07 2007
@@ -47,8 +47,10 @@
 def file_below_module(mod, subpath):
     return os.path.join(module_path(mod), *subpath.split('/'))
 
+
+
 def load_plugins(*names):
-    for name in names:
+    def load(name):
         for entry_point in iter_entry_points('kss.plugin', name):
             plugin_factory = entry_point.load()
 
@@ -57,6 +59,11 @@
             # Setup of all hooks
             plugin.register_commandsets(command_set_registry)
             plugin.register_selectors()
+            return
+        raise KeyError("Plugin is not registered: %s" % name)
+
+    for name in names:
+        load(name)
 
 def unload_plugins(*names):
     for name in names:

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    Mon Oct 15 09:47:07 2007
@@ -49,6 +49,13 @@
 
 We can also register additional selectors. 
 
+If we try the activate our plugin now it will not work.
+
+  >>> kss.base.load_plugins('kss-testing')
+  Traceback (most recent call last):
+  ...
+  KeyError: 'Plugin is not registered: kss-testing'
+
 Now that we have our registration it is time to hook it up with the
 setuptools registry.
 

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      Mon Oct 15 09:47:07 2007
@@ -1,6 +1,5 @@
 import unittest
 import doctest
-from kss.base.plugin import unload_plugins, activated_plugins
 
 def test_suite():
     suite = unittest.TestSuite((
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to