New plugin hooks: extra_css_urls() and extra_js_urls()

Closes #214
This commit is contained in:
Simon Willison 2018-04-17 20:12:21 -07:00
commit 1c36d07dd4
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
6 changed files with 117 additions and 7 deletions

View file

@ -113,6 +113,19 @@ def prepare_connection(conn):
"select convert_units(100, 'm', 'ft');"
return (amount * ureg(from_)).to(to_).to_tuple()[0]
conn.create_function('convert_units', 3, convert_units)
@hookimpl
def extra_css_urls():
return ['https://example.com/app.css']
@hookimpl
def extra_js_urls():
return [{
'url': 'https://example.com/app.js',
'sri': 'SRIHASH',
}]
'''
TABLES = '''

View file

@ -333,6 +333,19 @@ def test_view_html(app_client):
assert expected == [[str(td) for td in tr.select('td')] for tr in table.select('tbody tr')]
def test_plugin_extra_css_urls(app_client):
response = app_client.get('/', gather_request=False)
assert b'<link rel="stylesheet" href="https://example.com/app.css">' in response.body
def test_plugin_extra_js_urls(app_client):
response = app_client.get('/', gather_request=False)
assert (
b'<script src="https://example.com/app.js" integrity="SRIHASH" crossorigin="anonymous"></script>'
in response.body
)
def test_index_metadata(app_client):
response = app_client.get('/', gather_request=False)
assert response.status == 200