Author: jvloothuis
Date: Tue Aug 28 12:22:29 2007
New Revision: 46082

Added:
   kukit/kss.base/trunk/kss/base/EXTERNALS.txt
   kukit/kss.base/trunk/kss/base/compression/
      - copied from r46031, 
kukit/kss.concatresource/trunk/kss/concatresource/compression/
   kukit/kss.base/trunk/kss/base/compression/__init__.py
      - copied unchanged from r46070, 
kukit/kss.concatresource/trunk/kss/concatresource/compression/__init__.py
   kukit/kss.base/trunk/kss/base/compression/css.py
      - copied unchanged from r46070, 
kukit/kss.concatresource/trunk/kss/concatresource/compression/css.py
   kukit/kss.base/trunk/kss/base/compression/javascript.py
      - copied unchanged from r46070, 
kukit/kss.concatresource/trunk/kss/concatresource/compression/javascript.py
   kukit/kss.base/trunk/kss/base/compression/thirdparty/
      - copied from r46070, 
kukit/kss.concatresource/trunk/kss/concatresource/compression/thirdparty/
   kukit/kss.base/trunk/kss/base/coreselectors.py
   kukit/kss.base/trunk/kss/base/javascript.py
   kukit/kss.base/trunk/kss/base/plugin.py
Modified:
   kukit/kss.base/trunk/kss/base/   (props changed)
   kukit/kss.base/trunk/kss/base/README.txt
   kukit/kss.base/trunk/kss/base/__init__.py
   kukit/kss.base/trunk/kss/base/commands.py
   kukit/kss.base/trunk/kss/base/commandset.py
   kukit/kss.base/trunk/kss/base/corecommands.py
   kukit/kss.base/trunk/kss/base/registry.py
   kukit/kss.base/trunk/kss/base/selectors.py
   kukit/kss.base/trunk/kss/base/selectors.txt
   kukit/kss.base/trunk/setup.py
Log:

Converted to the new plugin system. This means that plugins are
registered as classes (with an entry point). End user code is simpler
because you can just initialize a plugin.

The base package now also distributes the kukit js (and the dependencies).


Added: kukit/kss.base/trunk/kss/base/EXTERNALS.txt
==============================================================================
--- (empty file)
+++ kukit/kss.base/trunk/kss/base/EXTERNALS.txt Tue Aug 28 12:22:29 2007
@@ -0,0 +1,5 @@
+# created by: svn propset svn:externals -F ./EXTERNALS.txt .
+#
+
+# kss related packages
+kukit https://codespeak.net/svn/kukit/kukit.js/trunk

Modified: kukit/kss.base/trunk/kss/base/README.txt
==============================================================================
--- kukit/kss.base/trunk/kss/base/README.txt    (original)
+++ kukit/kss.base/trunk/kss/base/README.txt    Tue Aug 28 12:22:29 2007
@@ -21,7 +21,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.selectors import CSS
+  >>> 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
@@ -126,9 +126,9 @@
 
 Now we will look at the individual methods provided by the core commands.
 
-  >>> core.replace_inner_html(CSS('div'), 'some <h1>html</h1>')
+  >>> core.replaceInnerHTML(CSS('div'), 'some <h1>html</h1>')
   >>> commands.render()
-  '...replaceInnerHTML...some <h1>html</h1>...'
+  '...replaceInnerHTML...some &amp;lt;h1&amp;gt;html&amp;lt;/h1&amp;gt;...'
 
 Using command sets
 ==================
@@ -153,8 +153,8 @@
 
 We can now access the command set.
 
-  >>> core = commands.get('core')
+  >>> core = commands.lookup('core')
 
 This command set is initialized and ready for usage.
 
-  >>> core.replace_inner_html(CSS('div'), 'example')
+  >>> core.replaceInnerHTML(CSS('div'), 'example')

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   Tue Aug 28 12:22:29 2007
@@ -7,3 +7,4 @@
 
 
 from kss.base.commands import KSSCommands
+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   Tue Aug 28 12:22:29 2007
@@ -52,7 +52,7 @@
         output.append(kss_response_footer)
         return ''.join(output)
 
-    def get(self, name):
+    def lookup(self, name):
         return command_set_registry.get(name)(self)
 
     def __str__(self):

Modified: kukit/kss.base/trunk/kss/base/commandset.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/commandset.py (original)
+++ kukit/kss.base/trunk/kss/base/commandset.py Tue Aug 28 12:22:29 2007
@@ -12,3 +12,10 @@
 
     def get(self, name):
         return self._sets[name]
+
+    def items(self):
+        return self._sets.iteritems()
+
+
+class PluginRegistry(CommandSetRegistry):
+    pass

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       Tue Aug 28 12:22:29 2007
@@ -1,10 +1,11 @@
 from kss.base.commands import KSSCommandSet
 
 class KSSCoreCommands(KSSCommandSet):
-    def replace_inner_html(self, selector, value):
+    
+    def replaceInnerHTML(self, selector, value):
         self.commands.add('replaceInnerHTML', selector, html=value)
 
-    def replace_html(self, selector, value):
+    def replaceHTML(self, selector, value):
         self.commands.add('replaceHTML', selector, html=value)
 
     def insert_html_after(self, selector, value):

Added: kukit/kss.base/trunk/kss/base/coreselectors.py
==============================================================================
--- (empty file)
+++ kukit/kss.base/trunk/kss/base/coreselectors.py      Tue Aug 28 12:22:29 2007
@@ -0,0 +1,17 @@
+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)

Added: kukit/kss.base/trunk/kss/base/javascript.py
==============================================================================
--- (empty file)
+++ kukit/kss.base/trunk/kss/base/javascript.py Tue Aug 28 12:22:29 2007
@@ -0,0 +1,32 @@
+import os
+
+from kss.base.plugin import activated_plugins
+from kss.base.compression.javascript import compress
+
+def concatinated():
+    '''Concatinate the Javascript files for all activate plugins'''
+    scripts = []
+    for id, plugin in activated_plugins():
+        for filename in plugin.javascripts:
+            f = open(filename, 'r')
+            scripts.append(f.read())
+            f.close()
+
+    return '\n'.join(scripts)
+
+def packed(compression_level=None):
+    return compress(concatinated(), compression_level)
+
+def extra_scripts():
+    '''Return a dictionary of the extra javascripts for all activated
+       plugins'''
+
+    scripts = {}
+    for id, plugin in activated_plugins():
+        for filename in plugin.extra_javascripts:
+            f = open(filename, 'r')
+            scripts[os.path.basename(filename)] = f.read()
+            f.close()
+    return scripts
+    
+ 

Added: kukit/kss.base/trunk/kss/base/plugin.py
==============================================================================
--- (empty file)
+++ kukit/kss.base/trunk/kss/base/plugin.py     Tue Aug 28 12:22:29 2007
@@ -0,0 +1,91 @@
+import os
+
+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
+
+class Plugin(object):
+    def register_commandsets(self, registry):
+        for name, commandset in self.commandsets.iteritems():
+            registry.register(name, commandset)
+
+    def register_selectors(self):
+        for selector in self.selectors:
+            setattr(kss_selectors, selector.__name__, selector)
+
+def javascripts_from(path):
+    javascripts = []
+    if os.path.isdir(path):
+        for dirpath, dirnames, filenames in os.walk(path):
+            for filename in filenames:
+                if filename.endswith('.js'):
+                    javascripts.append(os.path.join(dirpath, filename))
+    else:
+       if path.endswith('.js'):
+           javascripts.append(os.path.abspath(path))
+       else:
+           return javascripts_from(os.path.dirname(os.path.abspath(path)))
+    return javascripts
+
+def load_plugins(*names):
+    for name in names:
+        for entry_point in iter_entry_points('kss.plugin', name):
+            plugin_factory = entry_point.load()
+
+            plugin = plugin_factory()
+            plugin_registry.register(name, plugin)
+            # Setup of all hooks
+            plugin.register_commandsets(command_set_registry)
+            plugin.register_selectors()
+
+
+def activated_plugins():
+    return plugin_registry.items()
+
+
+
+# !TODO: Move to a seperate file
+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')
+
+core_js = ['utils.js',
+           'errors.js',
+           'oper.js',
+           'kukit.js',
+           'tokenizer.js',
+           'providerreg.js',
+           'resourcedata.js',
+           'kssparser.js',
+           'eventreg.js',
+           'actionreg.js',
+           'dom.js',
+           'commandreg.js',
+           'serveraction.js',
+           'requestmanager.js',
+           'commandprocessor.js',
+           'selectorreg.js',
+           'forms.js',
+           'plugin.js',
+           ]
+
+
+class KSSCore(Plugin):
+    '''The KSS core plugin has all the standard functionality'''
+
+    javascripts = [os.path.join(kukit_dir, 'kukit', js) for js in core_js]
+    
+    extra_javascripts = javascripts_from(os.path.join(kukit_dir, '3rd_party'))
+
+    commandsets = {
+        'core': KSSCoreCommands,
+        }
+
+    selectors = [CSS, HTMLId, SameNode, ParentNode]
+
+    # OPTIONAL!
+    events={}
+    actions=[]
+    value_providers = []

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   Tue Aug 28 12:22:29 2007
@@ -1,4 +1,4 @@
 from kss.base.commandset import CommandSetRegistry
 
 command_set_registry = CommandSetRegistry()
-
+plugin_registry = CommandSetRegistry()

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  Tue Aug 28 12:22:29 2007
@@ -5,19 +5,3 @@
 
     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)

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 Tue Aug 28 12:22:29 2007
@@ -1,6 +1,9 @@
 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.
@@ -24,7 +27,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.selectors import CSS, HTMLId
+  >>> from kss.base.coreselectors import CSS, HTMLId
 
 They both need a value to operate on.
 
@@ -44,7 +47,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.selectors import SameNode
+  >>> from kss.base.coreselectors import SameNode
   >>> selector = SameNode()
   >>> selector.type
   'samenode'
@@ -55,7 +58,7 @@
 query which only operates on nodes that are the parent (or
 grandparents).
 
-  >>> from kss.base.selectors import ParentNode
+  >>> from kss.base.coreselectors import ParentNode
   >>> selector = ParentNode('a')
   >>> selector.type
   'parentnode'
@@ -67,6 +70,8 @@
 
 For testing purposes we have a string representation of the selectors.
 
+!TODO: Fix lower casing of string representation
+
   >>> print Selector('type', 'value')
   type('value')
 

Modified: kukit/kss.base/trunk/setup.py
==============================================================================
--- kukit/kss.base/trunk/setup.py       (original)
+++ kukit/kss.base/trunk/setup.py       Tue Aug 28 12:22:29 2007
@@ -26,8 +26,8 @@
           'setuptools',
       ],
       entry_points={
-        'kss.commandset': [
-            'core=kss.base.corecommands:KSSCoreCommands'
+        'kss.plugin': [
+            'kss-core=kss.base.plugin:KSSCore'
             ],
         },
       test_suite='kss.base.tests.test_suite',
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to