mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
parent
b55809a1e2
commit
b52171db1e
4 changed files with 41 additions and 11 deletions
|
|
@ -1303,16 +1303,22 @@ class Datasette:
|
|||
def app(self):
|
||||
app = Sanic(__name__)
|
||||
default_templates = str(app_root / 'datasette' / 'templates')
|
||||
template_paths = []
|
||||
if self.template_dir:
|
||||
template_loader = ChoiceLoader([
|
||||
FileSystemLoader([self.template_dir, default_templates]),
|
||||
# Support {% extends "default:table.html" %}:
|
||||
PrefixLoader({
|
||||
'default': FileSystemLoader(default_templates),
|
||||
}, delimiter=':')
|
||||
])
|
||||
else:
|
||||
template_loader = FileSystemLoader(default_templates)
|
||||
template_paths.append(self.template_dir)
|
||||
template_paths.extend([
|
||||
plugin['templates_path']
|
||||
for plugin in get_plugins(pm)
|
||||
if plugin['templates_path']
|
||||
])
|
||||
template_paths.append(default_templates)
|
||||
template_loader = ChoiceLoader([
|
||||
FileSystemLoader(template_paths),
|
||||
# Support {% extends "default:table.html" %}:
|
||||
PrefixLoader({
|
||||
'default': FileSystemLoader(default_templates),
|
||||
}, delimiter=':')
|
||||
])
|
||||
self.jinja_env = Environment(
|
||||
loader=template_loader,
|
||||
autoescape=True,
|
||||
|
|
@ -1344,7 +1350,8 @@ class Datasette:
|
|||
app.add_route(
|
||||
JsonDataView.as_view(self, 'plugins.json', lambda: [{
|
||||
'name': p['name'],
|
||||
'static': p['static_path'] is not None
|
||||
'static': p['static_path'] is not None,
|
||||
'templates': p['templates_path'] is not None,
|
||||
} for p in get_plugins(pm)]),
|
||||
'/-/plugins<as_json:(\.json)?$>'
|
||||
)
|
||||
|
|
|
|||
|
|
@ -690,14 +690,18 @@ def get_plugins(pm):
|
|||
plugins = []
|
||||
for plugin in pm.get_plugins():
|
||||
static_path = None
|
||||
templates_path = None
|
||||
try:
|
||||
if pkg_resources.resource_isdir(plugin.__name__, 'static'):
|
||||
static_path = pkg_resources.resource_filename(plugin.__name__, 'static')
|
||||
if pkg_resources.resource_isdir(plugin.__name__, 'templates'):
|
||||
templates_path = pkg_resources.resource_filename(plugin.__name__, 'templates')
|
||||
except (KeyError, ImportError):
|
||||
# Caused by --plugins_dir= plugins - KeyError/ImportError thrown in Py3.5
|
||||
pass
|
||||
plugins.append({
|
||||
'name': plugin.__name__,
|
||||
'static_path': static_path,
|
||||
'templates_path': templates_path,
|
||||
})
|
||||
return plugins
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue