kopia lustrzana https://github.com/simonw/datasette
/-/plugins now shows details of hooks, closes #794
Also added /-/plugins?all=1 parameter to see default plugins.writable-canned
rodzic
9dd6d1ae6d
commit
69aa0277f5
|
@ -626,9 +626,9 @@ class Datasette:
|
|||
},
|
||||
}
|
||||
|
||||
def _plugins(self, show_all=False):
|
||||
def _plugins(self, request):
|
||||
ps = list(get_plugins())
|
||||
if not show_all:
|
||||
if not request.args.get("all"):
|
||||
ps = [p for p in ps if p["name"] not in DEFAULT_PLUGINS]
|
||||
return [
|
||||
{
|
||||
|
@ -636,6 +636,7 @@ class Datasette:
|
|||
"static": p["static_path"] is not None,
|
||||
"templates": p["templates_path"] is not None,
|
||||
"version": p.get("version"),
|
||||
"hooks": p["hooks"],
|
||||
}
|
||||
for p in ps
|
||||
]
|
||||
|
@ -823,7 +824,9 @@ class Datasette:
|
|||
r"/-/versions(?P<as_format>(\.json)?)$",
|
||||
)
|
||||
add_route(
|
||||
JsonDataView.as_asgi(self, "plugins.json", self._plugins),
|
||||
JsonDataView.as_asgi(
|
||||
self, "plugins.json", self._plugins, needs_request=True
|
||||
),
|
||||
r"/-/plugins(?P<as_format>(\.json)?)$",
|
||||
)
|
||||
add_route(
|
||||
|
|
|
@ -49,6 +49,7 @@ def get_plugins():
|
|||
"name": plugin.__name__,
|
||||
"static_path": static_path,
|
||||
"templates_path": templates_path,
|
||||
"hooks": [h.name for h in pm.get_hookcallers(plugin)],
|
||||
}
|
||||
distinfo = plugin_to_distinfo.get(plugin)
|
||||
if distinfo:
|
||||
|
|
|
@ -78,10 +78,13 @@ Shows a list of currently installed plugins and their versions. `Plugins example
|
|||
"name": "datasette_cluster_map",
|
||||
"static": true,
|
||||
"templates": false,
|
||||
"version": "0.4"
|
||||
"version": "0.10",
|
||||
"hooks": ["extra_css_urls", "extra_js_urls", "extra_body_script"]
|
||||
}
|
||||
]
|
||||
|
||||
Add ``?all=1`` to include details of the default plugins baked into Datasette.
|
||||
|
||||
.. _JsonDataView_config:
|
||||
|
||||
/-/config
|
||||
|
|
|
@ -1260,14 +1260,59 @@ def test_threads_json(app_client):
|
|||
def test_plugins_json(app_client):
|
||||
response = app_client.get("/-/plugins.json")
|
||||
expected = [
|
||||
{"name": name, "static": False, "templates": False, "version": None}
|
||||
for name in (
|
||||
"messages_output_renderer.py",
|
||||
"my_plugin.py",
|
||||
"my_plugin_2.py",
|
||||
"register_output_renderer.py",
|
||||
"view_name.py",
|
||||
)
|
||||
{
|
||||
"name": "messages_output_renderer.py",
|
||||
"static": False,
|
||||
"templates": False,
|
||||
"version": None,
|
||||
"hooks": ["register_output_renderer"],
|
||||
},
|
||||
{
|
||||
"name": "my_plugin.py",
|
||||
"static": False,
|
||||
"templates": False,
|
||||
"version": None,
|
||||
"hooks": [
|
||||
"actor_from_request",
|
||||
"extra_body_script",
|
||||
"extra_css_urls",
|
||||
"extra_js_urls",
|
||||
"extra_template_vars",
|
||||
"permission_allowed",
|
||||
"prepare_connection",
|
||||
"prepare_jinja2_environment",
|
||||
"register_facet_classes",
|
||||
"render_cell",
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "my_plugin_2.py",
|
||||
"static": False,
|
||||
"templates": False,
|
||||
"version": None,
|
||||
"hooks": [
|
||||
"actor_from_request",
|
||||
"asgi_wrapper",
|
||||
"extra_js_urls",
|
||||
"extra_template_vars",
|
||||
"permission_allowed",
|
||||
"render_cell",
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "register_output_renderer.py",
|
||||
"static": False,
|
||||
"templates": False,
|
||||
"version": None,
|
||||
"hooks": ["register_output_renderer"],
|
||||
},
|
||||
{
|
||||
"name": "view_name.py",
|
||||
"static": False,
|
||||
"templates": False,
|
||||
"version": None,
|
||||
"hooks": ["extra_template_vars"],
|
||||
},
|
||||
]
|
||||
assert expected == sorted(response.json, key=lambda p: p["name"])
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue