render_cell(value) plugin hook, closes #352

New plugin hook for customizing the way cells values are rendered in HTML.

The first full example of this hook in use is https://github.com/simonw/datasette-json-html
This commit is contained in:
Simon Willison 2018-08-04 17:14:56 -07:00 committed by GitHub
commit 4ac9132240
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 150 additions and 30 deletions

View file

@ -3,6 +3,7 @@ from .fixtures import ( # noqa
app_client,
)
import pytest
import urllib
def test_plugins_dir_plugin(app_client):
@ -67,3 +68,20 @@ def test_plugins_with_duplicate_js_urls(app_client):
) < srcs.index(
'https://example.com/plugin2.js'
)
def test_plugins_render_cell(app_client):
sql = """
select '{"href": "http://example.com/", "label":"Example"}'
""".strip()
path = "/fixtures?" + urllib.parse.urlencode({
"sql": sql,
})
response = app_client.get(path)
td = Soup(
response.body, "html.parser"
).find("table").find("tbody").find("td")
a = td.find("a")
assert a is not None, str(a)
assert a.attrs["href"] == "http://example.com/"
assert a.text == "Example"