Author: jvloothuis Date: Sat May 12 13:58:21 2007 New Revision: 43288 Added: kukit/kss.commands/trunk/kss/ kukit/kss.commands/trunk/kss/__init__.py kukit/kss.commands/trunk/kss/commands/ kukit/kss.commands/trunk/kss/commands/README.txt kukit/kss.commands/trunk/kss/commands/__init__.py kukit/kss.commands/trunk/kss/commands/commands.py kukit/kss.commands/trunk/kss/commands/selectors.py kukit/kss.commands/trunk/kss/commands/selectors.txt kukit/kss.commands/trunk/kss/commands/tests.py kukit/kss.commands/trunk/setup.py Log: Start of implementation of the pure Python KSS support package
Added: kukit/kss.commands/trunk/kss/__init__.py ============================================================================== --- (empty file) +++ kukit/kss.commands/trunk/kss/__init__.py Sat May 12 13:58:21 2007 @@ -0,0 +1,6 @@ +# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages +try: + __import__('pkg_resources').declare_namespace(__name__) +except ImportError: + from pkgutil import extend_path + __path__ = extend_path(__path__, __name__) Added: kukit/kss.commands/trunk/kss/commands/README.txt ============================================================================== --- (empty file) +++ kukit/kss.commands/trunk/kss/commands/README.txt Sat May 12 13:58:21 2007 @@ -0,0 +1,39 @@ +KSS Commands +============ + +The KSS commands system allows you to create a properly formatted KSS +response. + +Command renderer +================ + +The command renderer is the core of the system. This object is responsible +for create the KSS response. We will now take a look at an example to see it +in action. + + >>> from kss.commands import KSSCommands + +The constructor takes no arguments. + + >>> commands = KSSCommands() + +We can add commands to the renderer using the `add` method. To do this we +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.commands.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 +which will be invoked on the client. Our second argument is the selector. +Any given keyword arguments become arguments to the client side action. + +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') + +Now that we have a few commands we can render them. + + >>> commands.render() + 'some kss data' Added: kukit/kss.commands/trunk/kss/commands/__init__.py ============================================================================== --- (empty file) +++ kukit/kss.commands/trunk/kss/commands/__init__.py Sat May 12 13:58:21 2007 @@ -0,0 +1,9 @@ +# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages +try: + __import__('pkg_resources').declare_namespace(__name__) +except ImportError: + from pkgutil import extend_path + __path__ = extend_path(__path__, __name__) + +from commands import KSSCommands +from selectors import Selector Added: kukit/kss.commands/trunk/kss/commands/commands.py ============================================================================== --- (empty file) +++ kukit/kss.commands/trunk/kss/commands/commands.py Sat May 12 13:58:21 2007 @@ -0,0 +1,10 @@ +class KSSCommands(object): + '''Command renderer for creating KSS responses''' + def __init__(self): + self.commands = [] + + def add(self, action, selector, **kwargs): + self.commands.append((action, selector, kwargs)) + + def render(self): + return 'some kss data' Added: kukit/kss.commands/trunk/kss/commands/selectors.py ============================================================================== --- (empty file) +++ kukit/kss.commands/trunk/kss/commands/selectors.py Sat May 12 13:58:21 2007 @@ -0,0 +1,20 @@ +class Selector(object): + def __init__(self, type, value): + self.type = type + self.value = 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) Added: kukit/kss.commands/trunk/kss/commands/selectors.txt ============================================================================== --- (empty file) +++ kukit/kss.commands/trunk/kss/commands/selectors.txt Sat May 12 13:58:21 2007 @@ -0,0 +1,62 @@ +Selectors +========= + +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. + +A base class is provided for all selectors. + + >>> from kss.commands import Selector + >>> selector = Selector('type', 'value') + +The selector now has a type and value property. + + >>> selector.type + 'type' + + >>> selector.value + 'value' + +Standard selectors +------------------ + +In the core package you can find a few standard selectors. The most basic +selectors are the CSS and HTML id selectors. + + >>> from kss.commands.selectors import CSS, HTMLId + +They both need a value to operate on. + + >>> selector = CSS('div.main a') + >>> selector.type + 'css' + >>> selector.value + 'div.main a' + + >>> selector = HTMLId('someid') + >>> selector.type + 'htmlid' + >>> selector.value + 'someid' + +There are also two somewhat different selectors. The first is special 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.commands.selectors import SameNode + >>> selector = SameNode() + >>> selector.type + 'samenode' + >>> selector.value + '' + +Another core selector is parentnode. This one can be used to use a CSS query +which only operates on nodes that are the parent (or grandparents). + + >>> from kss.commands.selectors import ParentNode + >>> selector = ParentNode('a') + >>> selector.type + 'parentnode' + >>> selector.value + 'a' Added: kukit/kss.commands/trunk/kss/commands/tests.py ============================================================================== --- (empty file) +++ kukit/kss.commands/trunk/kss/commands/tests.py Sat May 12 13:58:21 2007 @@ -0,0 +1,12 @@ +import unittest +import doctest + +def test_suite(): + suite = unittest.TestSuite(( + doctest.DocFileSuite( + 'README.txt', 'selectors.txt', + package='kss.commands', + optionflags=doctest.ELLIPSIS, + ), + )) + return suite Added: kukit/kss.commands/trunk/setup.py ============================================================================== --- (empty file) +++ kukit/kss.commands/trunk/setup.py Sat May 12 13:58:21 2007 @@ -0,0 +1,32 @@ +from setuptools import setup, find_packages +import sys, os + +version = '0.1' + +setup(name='kss.commands', + version=version, + description="KSS (Kinetic Style Sheets) commands framework", + long_description="""\ +""", + # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers + classifiers=[ + "Programming Language :: Python", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + keywords='', + author='KSS Project', + author_email='[EMAIL PROTECTED]', + url='http://kssproject.org', + license='GPL', + packages=find_packages(exclude=['ez_setup']), + namespace_packages=['kss'], + include_package_data=True, + zip_safe=False, + install_requires=[ + 'setuptools', + ], + entry_points=""" + # -*- Entry points: -*- + """, + test_suite='kss.commands.tests.test_suite', + ) _______________________________________________ Kukit-checkins mailing list [email protected] http://codespeak.net/mailman/listinfo/kukit-checkins
