datasette-vega/datasette_vega/__init__.py
Simon Willison 033ee204bb Applied Black
2020-09-03 19:34:52 -07:00

28 lines
700 B
Python

from datasette import hookimpl
import glob
import os
cache = {}
static_dir = os.path.join(os.path.dirname(__file__), "static")
def cached_filepaths_for_extension(extension):
pattern = os.path.join(static_dir, "*.{}".format(extension))
if pattern not in cache:
cache[pattern] = [
"/-/static-plugins/datasette_vega/{}".format(os.path.basename(g))
for g in glob.glob(pattern)
]
return cache[pattern]
@hookimpl
def extra_css_urls(view_name):
if view_name == "table":
return cached_filepaths_for_extension("css")
@hookimpl
def extra_js_urls(view_name):
if view_name == "table":
return cached_filepaths_for_extension("js")