.add_database() and .remove_database() methods, refs #671

Also made a start on the Datasette class documentation, refs #576
This commit is contained in:
Simon Willison 2020-02-13 17:25:27 -08:00
commit 3ffb8f3b98
4 changed files with 60 additions and 6 deletions

View file

@ -278,6 +278,8 @@ If you are publishing your data using the :ref:`datasette publish <cli_publish>`
--plugin-secret datasette-auth-github client_id your_client_id \
--plugin-secret datasette-auth-github client_secret your_client_secret
.. _plugins_plugin_config:
Writing plugins that accept configuration
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -320,6 +322,8 @@ The plugin configuration could also be set at the top level of ``metadata.json``
Now that ``datasette-cluster-map`` plugin configuration will apply to every table in every database.
.. _plugin_hooks:
Plugin hooks
------------
@ -399,7 +403,7 @@ extra_css_urls(template, database, table, datasette)
``table`` - string or None
The name of the table
``datasette`` - Datasette instance
``datasette`` - :ref:`datasette`
You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
Return a list of extra CSS URLs that should be included on the page. These can
@ -535,7 +539,7 @@ Lets you customize the display of values within table cells in the HTML table vi
``database`` - string
The name of the database
``datasette`` - Datasette instance
``datasette`` - :ref:`datasette`
You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
If your hook returns ``None``, it will be ignored. Use this to indicate that your hook is not able to custom render this particular value.
@ -605,7 +609,7 @@ Extra JavaScript to be added to a ``<script>`` block at the end of the ``<body>`
``view_name`` - string
The name of the view being displayed. (`index`, `database`, `table`, and `row` are the most important ones.)
``datasette`` - Datasette instance
``datasette`` - :ref:`datasette`
You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
The ``template``, ``database`` and ``table`` options can be used to return different code depending on which template is being rendered and which database or table are being processed.
@ -637,7 +641,7 @@ Extra template variables that should be made available in the rendered template
``request`` - object
The current HTTP request object. ``request.scope`` provides access to the ASGI scope.
``datasette`` - Datasette instance
``datasette`` - :ref:`datasette`
You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
This hook can return one of three different types:
@ -682,7 +686,7 @@ You can then use the new function in a template like so::
register_output_renderer(datasette)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``datasette`` - Datasette instance
``datasette`` - :ref:`datasette`
You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
Allows the plugin to register a new output renderer, to output data in a custom format. The hook function should return a dictionary, or a list of dictionaries, which contain the file extension you want to handle and a callback function: