CSS is now registered with Tiki
This commit is contained in:
Родитель
613f55e4af
Коммит
6b29fbaac6
|
@ -37,6 +37,7 @@ from paste.auth import auth_tkt
|
||||||
from paste.proxy import Proxy
|
from paste.proxy import Proxy
|
||||||
import simplejson
|
import simplejson
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import static
|
||||||
from webob import Request, Response
|
from webob import Request, Response
|
||||||
|
|
||||||
from bespin.config import c
|
from bespin.config import c
|
||||||
|
@ -1129,7 +1130,18 @@ def _plugin_response(response, path=None, plugin_list=None):
|
||||||
"id": "%s:%s" % (name, scriptname)}
|
"id": "%s:%s" % (name, scriptname)}
|
||||||
)
|
)
|
||||||
|
|
||||||
item = {"depends": plugin.depends, "scripts": scripts}
|
stylesheets = []
|
||||||
|
for stylesheet in plugin.stylesheets:
|
||||||
|
if plugin.location_name == "user":
|
||||||
|
url = "/server/file/at/%s%%3A%s" % (
|
||||||
|
plugin.relative_location, stylesheet)
|
||||||
|
else:
|
||||||
|
url = "/server/plugin/file/%s/%s/%s" % (
|
||||||
|
plugin.location_name, name, stylesheet)
|
||||||
|
stylesheets.append(url)
|
||||||
|
|
||||||
|
item = {"depends": plugin.depends, "scripts": scripts,
|
||||||
|
"stylesheets": stylesheets}
|
||||||
parts.append("""; tiki.register('%s', %s)""" % (name, simplejson.dumps(item)))
|
parts.append("""; tiki.register('%s', %s)""" % (name, simplejson.dumps(item)))
|
||||||
metadata[name] = plugin.metadata
|
metadata[name] = plugin.metadata
|
||||||
parts.append("""; tiki.require("bespin:plugins").catalog.load(%s);""" % simplejson.dumps(metadata))
|
parts.append("""; tiki.require("bespin:plugins").catalog.load(%s);""" % simplejson.dumps(metadata))
|
||||||
|
@ -1201,6 +1213,34 @@ def load_script(request, response):
|
||||||
response.body = _wrap_script(plugin_name, script_path, script_text)
|
response.body = _wrap_script(plugin_name, script_path, script_text)
|
||||||
return response()
|
return response()
|
||||||
|
|
||||||
|
@expose(r'^/plugin/file/(?P<plugin_location>[^/]+)/(?P<plugin_name>[^/]+)/(?P<path>.*)', 'GET', auth=False)
|
||||||
|
def load_file(request, response):
|
||||||
|
plugin_name = request.kwargs['plugin_name']
|
||||||
|
plugin_location = request.kwargs['plugin_location']
|
||||||
|
script_path = request.kwargs['path']
|
||||||
|
if ".." in plugin_name or ".." in script_path or ".." in plugin_location:
|
||||||
|
raise BadRequest("'..' not allowed in plugin or script names")
|
||||||
|
|
||||||
|
path = None
|
||||||
|
for path_entry in c.plugin_path:
|
||||||
|
if path_entry['name'] == plugin_location:
|
||||||
|
path = path_entry
|
||||||
|
|
||||||
|
if path is None:
|
||||||
|
raise FileNotFound("Plugin location %s unknown" % (plugin_location))
|
||||||
|
|
||||||
|
plugin = plugins.lookup_plugin(plugin_name, [path])
|
||||||
|
if not plugin:
|
||||||
|
response.status = "404 Not Found"
|
||||||
|
response.content_type = "text/plain"
|
||||||
|
response.body = "Plugin " + plugin_name + " does not exist"
|
||||||
|
return response()
|
||||||
|
|
||||||
|
# use the static package to actually serve the file
|
||||||
|
newapp = static.Cling(plugin.location)
|
||||||
|
request.path_info = "/" + "/".join(request.path_info.split("/")[5:])
|
||||||
|
return newapp(request.environ, response.start_response)
|
||||||
|
|
||||||
@expose(r'^/plugin/reload/(?P<plugin_name>.+)', 'GET')
|
@expose(r'^/plugin/reload/(?P<plugin_name>.+)', 'GET')
|
||||||
def reload_plugin(request, response):
|
def reload_plugin(request, response):
|
||||||
response.content_type = "text/javascript"
|
response.content_type = "text/javascript"
|
||||||
|
@ -1303,7 +1343,6 @@ class URLRelayCompatibleProxy(Proxy):
|
||||||
|
|
||||||
def make_app():
|
def make_app():
|
||||||
from webob import Response
|
from webob import Response
|
||||||
import static
|
|
||||||
static_app = static.Cling(c.static_dir)
|
static_app = static.Cling(c.static_dir)
|
||||||
if c.static_override:
|
if c.static_override:
|
||||||
from paste.cascade import Cascade
|
from paste.cascade import Cascade
|
||||||
|
|
|
@ -60,13 +60,13 @@ class BespinRequest(Request):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
class BespinResponse(Response):
|
class BespinResponse(Response):
|
||||||
def __init__(self, environ, start_request, **kw):
|
def __init__(self, environ, start_response, **kw):
|
||||||
super(BespinResponse, self).__init__(**kw)
|
super(BespinResponse, self).__init__(**kw)
|
||||||
self.environ = environ
|
self.environ = environ
|
||||||
self.start_request = start_request
|
self.start_response = start_response
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
return super(BespinResponse, self).__call__(self.environ, self.start_request)
|
return super(BespinResponse, self).__call__(self.environ, self.start_response)
|
||||||
|
|
||||||
def error(self, status, e):
|
def error(self, status, e):
|
||||||
self.status = status
|
self.status = status
|
||||||
|
|
|
@ -91,18 +91,29 @@ class Plugin(object):
|
||||||
self._metadata = md
|
self._metadata = md
|
||||||
return md
|
return md
|
||||||
|
|
||||||
@property
|
def _putFilesInAttribute(self, attribute, glob):
|
||||||
def scripts(self):
|
"""Finds all of the plugin files matching the given glob
|
||||||
|
and puts them in the attribute given. If the
|
||||||
|
attribute is already set, it is returned directly."""
|
||||||
try:
|
try:
|
||||||
return self._scripts
|
return getattr(self, attribute)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
loc = self.location
|
loc = self.location
|
||||||
if loc.isdir():
|
if loc.isdir():
|
||||||
scripts = [loc.relpathto(f) for f in self.location.walkfiles("*.js")]
|
l = [loc.relpathto(f) for f in self.location.walkfiles(glob)]
|
||||||
else:
|
else:
|
||||||
scripts = [""]
|
l = [""]
|
||||||
self._scripts = scripts
|
setattr(self, attribute, l)
|
||||||
return scripts
|
return l
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def stylesheets(self):
|
||||||
|
return self._putFilesInAttribute("_stylesheets", "*.css")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def scripts(self):
|
||||||
|
return self._putFilesInAttribute("_scripts", "*.js")
|
||||||
|
|
||||||
def get_script_text(self, scriptname):
|
def get_script_text(self, scriptname):
|
||||||
"""Look up the script at scriptname within this plugin."""
|
"""Look up the script at scriptname within this plugin."""
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
body {}
|
|
@ -105,6 +105,10 @@ def test_plugin_metadata():
|
||||||
errors = p.errors
|
errors = p.errors
|
||||||
assert errors
|
assert errors
|
||||||
|
|
||||||
|
def test_plugin_stylesheets():
|
||||||
|
plugin = plugins.lookup_plugin("plugin1")
|
||||||
|
assert plugin.stylesheets == ["resources/foo/foo.css"]
|
||||||
|
|
||||||
def test_lookup_plugin():
|
def test_lookup_plugin():
|
||||||
plugin = plugins.lookup_plugin("DOES NOT EXIST")
|
plugin = plugins.lookup_plugin("DOES NOT EXIST")
|
||||||
assert plugin is None
|
assert plugin is None
|
||||||
|
@ -121,6 +125,7 @@ def test_default_plugin_registration():
|
||||||
assert response.content_type == "text/javascript"
|
assert response.content_type == "text/javascript"
|
||||||
assert "plugin1" in response.body
|
assert "plugin1" in response.body
|
||||||
assert "plugin/script/testplugins/plugin1/thecode.js" in response.body
|
assert "plugin/script/testplugins/plugin1/thecode.js" in response.body
|
||||||
|
assert "plugin/file/testplugins/plugin1/resources/foo/foo.css" in response.body
|
||||||
assert "NOT THERE" not in response.body
|
assert "NOT THERE" not in response.body
|
||||||
assert "plugin3" not in response.body
|
assert "plugin3" not in response.body
|
||||||
|
|
||||||
|
@ -141,6 +146,12 @@ def test_get_single_file_script():
|
||||||
assert "exports.someFunction" in response.body
|
assert "exports.someFunction" in response.body
|
||||||
assert "SingleFilePlugin1:index" in response.body
|
assert "SingleFilePlugin1:index" in response.body
|
||||||
|
|
||||||
|
def test_get_stylesheet():
|
||||||
|
response = app.get("/plugin/file/testplugins/plugin1/resources/foo/foo.css")
|
||||||
|
content_type = response.content_type
|
||||||
|
assert content_type == "text/css"
|
||||||
|
assert "body {}" in response.body
|
||||||
|
|
||||||
|
|
||||||
def test_bad_script_request():
|
def test_bad_script_request():
|
||||||
response = app.get("/plugin/script/testplugins/NOPLUGIN/somefile.js", status=404)
|
response = app.get("/plugin/script/testplugins/NOPLUGIN/somefile.js", status=404)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче