server now provides plugin metadata in JSON rather than as a script
This commit is contained in:
Родитель
d2c122ad3b
Коммит
546d657151
|
@ -74,6 +74,7 @@ c.current_domain_cookie = True
|
|||
c.template_path = [path(__file__).dirname().abspath()]
|
||||
|
||||
c.base_url = "https://bespin.mozilla.com/"
|
||||
c.server_base_url = "server/"
|
||||
|
||||
# Settings for sending email
|
||||
c.email_from = "invalid@ThisIsNotAValidEmailAddressUseSomethingElse.com"
|
||||
|
@ -238,6 +239,9 @@ def load_pyconfig(configfile):
|
|||
print(c.fsroot)
|
||||
|
||||
def activate_profile():
|
||||
if c.server_base_url and not c.server_base_url.endswith("/"):
|
||||
c.server_base_url += "/"
|
||||
|
||||
for ep in pkg_resources.iter_entry_points("bespin_extensions"):
|
||||
ep.load()
|
||||
|
||||
|
|
|
@ -1105,50 +1105,16 @@ def run_deploy(request, response):
|
|||
return response()
|
||||
|
||||
def _plugin_response(response, path=None, plugin_list=None):
|
||||
response.content_type = "text/javascript"
|
||||
response.content_type = "application/json"
|
||||
|
||||
parts = []
|
||||
metadata = dict()
|
||||
|
||||
if plugin_list is None:
|
||||
plugin_list = plugins.find_plugins(path)
|
||||
|
||||
metadata = dict((plugin.name, plugin.metadata)
|
||||
for plugin in plugin_list if not plugin.errors)
|
||||
|
||||
for plugin in plugin_list:
|
||||
if not plugin.errors:
|
||||
name = plugin.name
|
||||
|
||||
scripts = []
|
||||
for scriptname in plugin.scripts:
|
||||
if plugin.location_name == "user":
|
||||
url = "/server/getscript/file/at/%s%%3A%s" % (
|
||||
plugin.relative_location, scriptname)
|
||||
else:
|
||||
url = "/server/plugin/script/%s/%s/%s" % (
|
||||
plugin.location_name, name, scriptname)
|
||||
scripts.append(
|
||||
{"url": url,
|
||||
"id": "%s:%s" % (name, scriptname)}
|
||||
)
|
||||
|
||||
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": url,
|
||||
"id": "%s:%s" % (name, stylesheet)}
|
||||
)
|
||||
|
||||
item = {"depends": plugin.depends, "scripts": scripts,
|
||||
"stylesheets": stylesheets}
|
||||
parts.append("""; tiki.register('%s', %s)""" % (name, simplejson.dumps(item)))
|
||||
metadata[name] = plugin.metadata
|
||||
parts.append("""; tiki.require("bespin:plugins").catalog.load(%s);""" % simplejson.dumps(metadata))
|
||||
response.body = "\n".join(parts)
|
||||
response.body = simplejson.dumps(metadata)
|
||||
return response()
|
||||
|
||||
@expose(r'^/plugin/register/defaults$', 'GET', auth=False)
|
||||
|
|
|
@ -105,6 +105,40 @@ class Plugin(object):
|
|||
self._errors = ["Problem with metadata JSON: %s" % (e)]
|
||||
md = {}
|
||||
|
||||
server_base_url = config.c.server_base_url
|
||||
name = self.name
|
||||
|
||||
if self.location_name == "user":
|
||||
md['scripts'] = [
|
||||
dict(url="%sgetscript/file/at/%s%%3A%s" % (
|
||||
server_base_url, self.relative_location,
|
||||
scriptname),
|
||||
id="%s:%s" % (name, scriptname))
|
||||
for scriptname in self.scripts
|
||||
]
|
||||
md['stylesheets'] = [
|
||||
dict(url="%sfile/at/%s%%3A%s" % (
|
||||
server_base_url, self.relative_location,
|
||||
stylesheet),
|
||||
id="%s:%s" % (name, stylesheet))
|
||||
for stylesheet in self.stylesheets
|
||||
]
|
||||
else:
|
||||
md['scripts'] = [
|
||||
dict(url="%splugin/script/%s/%s/%s" % (
|
||||
server_base_url, self.location_name,
|
||||
name, scriptname),
|
||||
id="%s:%s" % (name, scriptname))
|
||||
for scriptname in self.scripts
|
||||
]
|
||||
md['stylesheets'] = [
|
||||
dict(url="%splugin/file/%s/%s/%s" % (
|
||||
server_base_url, self.location_name, name,
|
||||
stylesheet),
|
||||
id="%s:%s" % (name, stylesheet))
|
||||
for stylesheet in self.stylesheets
|
||||
]
|
||||
|
||||
self._metadata = md
|
||||
return md
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ def test_lookup_plugin():
|
|||
|
||||
def test_default_plugin_registration():
|
||||
response = app.get("/plugin/register/defaults")
|
||||
assert response.content_type == "text/javascript"
|
||||
assert response.content_type == "application/json"
|
||||
assert "plugin1" 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
|
||||
|
@ -221,7 +221,7 @@ def test_user_installed_plugins():
|
|||
response = app.put("/file/at/BespinSettings/plugins/BiggerPlugin/somedir/script.js",
|
||||
"exports.foo = 1;\n")
|
||||
response = app.get("/plugin/register/user")
|
||||
assert response.content_type == "text/javascript"
|
||||
assert response.content_type == "application/json"
|
||||
assert "MyPlugin" in response.body
|
||||
assert "BiggerPlugin" in response.body
|
||||
assert "file/at/BespinSettings/plugins/MyPlugin.js%3A" in response.body
|
||||
|
@ -234,7 +234,7 @@ def test_user_installed_plugins():
|
|||
"pluginOrdering": ["EditablePlugin"]
|
||||
}""")
|
||||
response = app.get("/plugin/register/user")
|
||||
assert response.content_type == "text/javascript"
|
||||
assert response.content_type == "application/json"
|
||||
assert "MyPlugin" in response.body
|
||||
assert "BiggerPlugin" in response.body
|
||||
assert "EditablePlugin" in response.body
|
||||
|
@ -253,7 +253,7 @@ def test_plugin_reload():
|
|||
_init_data()
|
||||
response = app.get("/plugin/reload/plugin2")
|
||||
print response.body
|
||||
assert '"plugin2": {}' in response.body
|
||||
assert '"plugin2": {' in response.body
|
||||
# just need the plugin, not its dependents
|
||||
assert '"depends": ["plugin2"]' not in response.body
|
||||
|
Загрузка…
Ссылка в новой задаче