Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass configuration to plugins? #401

Closed
dazzag24 opened this issue Jan 17, 2019 · 3 comments
Closed

How to pass configuration to plugins? #401

dazzag24 opened this issue Jan 17, 2019 · 3 comments

Comments

@dazzag24
Copy link

Hi,
Firstly, thanks for your work on datasette, it is a hugely useful tool!

I've been working on a fork [https://github.com/dazzag24/datasette-cluster-map] of datasette-cluster-map to allow the tileserver to be easily switched. Primarily because the tiles being served in the current version use localised text for labels and I'd like to have English used for these names instead.

It uses http://leaflet-extras.github.io/leaflet-providers/preview/ to allow you to simply set the tile provider using a call like so:

let tiles = L.tileLayer.provider('Esri.WorldTopoMap');

instead of the current:

let tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        maxZoom: 19,
        detectRetina: true,
        attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
    }),

However I've got stuck in trying to work out how to pass the provider string to the plugin.
In the documentation: https://datasette.readthedocs.io/en/stable/plugins.html you discuss configuration of plugins and use an example of passing in which latitude and longitude columns should be used. However I cannot seem to see anywhere in the current datasette-cluster-map code where these config params are passed in or used.

Can you please point me to an example or how to pass configuration from the metadata.json down into a plugin. Once I've over come this issue I was wondering if you would be interested in taking this change into your version?

Many thanks
Darren

@simonw
Copy link
Owner

simonw commented Jan 17, 2019

Datasette-cluster-map doesn't use the new plugin configuration mechanism yet - it really should!

The best example of how to use this mechanism right now is embedded in the Datasette unit tests:

datasette/tests/fixtures.py

Lines 266 to 270 in b7257a2

"config": datasette.plugin_config(
"name-of-plugin",
database=database,
table=table,
)

def test_plugin_config(app_client):
assert {"depth": "table"} == app_client.ds.plugin_config(
"name-of-plugin", database="fixtures", table="sortable"
)
assert {"depth": "database"} == app_client.ds.plugin_config(
"name-of-plugin", database="fixtures", table="unknown_table"
)

@simonw
Copy link
Owner

simonw commented Jan 18, 2019

I've released a new version of the datasette-cluster-map plugin to illustrate how plugin configuration can work: simonw/datasette-cluster-map@fcc86c4

@simonw simonw closed this as completed Jan 18, 2019
@dazzag24
Copy link
Author

Thanks. I'll take a look at your changes.
I must admit I was struggling to see how to pass info from the python code in init.py into the javascript document.addEventListener function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants