Author: jvloothuis
Date: Mon Jun 25 08:14:41 2007
New Revision: 44490
Added:
kukit/kss.pylons/trunk/kss/pylons/core.py
Modified:
kukit/kss.pylons/trunk/kss/pylons/middleware.py
kukit/kss.pylons/trunk/setup.py
Log:
Made the loading of Javascripts pluggable
Added: kukit/kss.pylons/trunk/kss/pylons/core.py
==============================================================================
--- (empty file)
+++ kukit/kss.pylons/trunk/kss/pylons/core.py Mon Jun 25 08:14:41 2007
@@ -0,0 +1,4 @@
+from kss.pylons.middleware import StaticJavascriptPlugin
+from kss.pylons.helpers import javascript_path
+
+core_javascripts = StaticJavascriptPlugin(javascript_path)
Modified: kukit/kss.pylons/trunk/kss/pylons/middleware.py
==============================================================================
--- kukit/kss.pylons/trunk/kss/pylons/middleware.py (original)
+++ kukit/kss.pylons/trunk/kss/pylons/middleware.py Mon Jun 25 08:14:41 2007
@@ -1,15 +1,41 @@
+from pkg_resources import iter_entry_points
import os
from paste.urlparser import StaticURLParser
-from kss.pylons.helpers import javascript_path
+from paste import httpexceptions
+from paste import request
class StaticKSSJavascripts(object):
def __init__(self):
+ javascript_plugins = {}
+ for entrypoint in iter_entry_points('kss.javascript'):
+ plugin = entrypoint.load()
+ javascript_plugins[entrypoint.name] = plugin
+ self.javascript_plugins = javascript_plugins
+
+
+ def __call__(self, environ, start_response):
+ found = environ.get('PATH_INFO', '').startswith
+ for id in self.javascript_plugins:
+ if found('/%s/' % id):
+ return self.javascript_plugins[id](environ, start_response)
+ return self.not_found(environ, start_response)
+
+ def not_found(self, environ, start_response):
+ exc = httpexceptions.HTTPNotFound(
+ 'The resource at %s could not be found'
+ % request.construct_url(environ),
+ comment='SCRIPT_NAME=%r; PATH_INFO=%r; using plugins: %s'
+ % (environ.get('SCRIPT_NAME'), environ.get('PATH_INFO'),
+ list(self.javascript_plugins)))
+ return exc.wsgi_application(environ, start_response)
+
+
+
+class StaticJavascriptPlugin(object):
+ def __init__(self, javascript_path):
self.javascripts_app = StaticURLParser(
os.path.dirname(javascript_path))
-
+
def __call__(self, environ, start_response):
- if environ.get('PATH_INFO', '').startswith('/kukit/'):
- return self.javascripts_app(environ, start_response)
- else:
- return self.javascripts_app.not_found(environ, start_response)
+ return self.javascripts_app(environ, start_response)
Modified: kukit/kss.pylons/trunk/setup.py
==============================================================================
--- kukit/kss.pylons/trunk/setup.py (original)
+++ kukit/kss.pylons/trunk/setup.py Mon Jun 25 08:14:41 2007
@@ -27,9 +27,11 @@
'kss.pluginregistry>=dev',
'kss.commands>=dev',
],
- entry_points="""
- # -*- Entry points: -*-
- """,
+ entry_points={
+ 'kss.javascript': [
+ 'kukit=kss.pylons.core:core_javascripts',
+ ]
+ },
test_suite='kss.pylons.tests.test_suite',
dependency_links=[
'https://codespeak.net/svn/kukit/kss.commands/trunk#egg=kss.commands-dev',
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins