Plugins can now bundle custom templates, closes #224

Refs #14
This commit is contained in:
Simon Willison 2018-04-18 22:50:27 -07:00
commit b52171db1e
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
4 changed files with 41 additions and 11 deletions

View file

@ -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