Skip to content

Commit

Permalink
rename static_paths and template_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Zsailer committed May 20, 2019
1 parent 1a68613 commit 9217cf9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
23 changes: 14 additions & 9 deletions jupyter_server/extension/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ def _default_extension_name(self, obj, value):
ServerApp
]

static_file_path = List(Unicode(),
help="""paths to search for serving static files for the extension."""
static_paths = List(Unicode(),
help="""paths to search for serving static files.
This allows adding javascript/css to be available from the notebook server machine,
or overriding individual files in the IPython
"""
).tag(config=True)

template_path = List(Unicode(),
help=_("""Paths to search for serving jinja templates for the extension.""")
template_paths = List(Unicode(),
help=_("""Paths to search for serving jinja templates.
Can be used to override templates from notebook.templates.""")
).tag(config=True)

settings = Dict(
Expand All @@ -70,18 +76,18 @@ def _default_extension_name(self, obj, value):

def initialize_static_handler(self):
# Check to see if
if len(self.static_file_path) > 0:
if len(self.static_paths) > 0:
# Append the extension's static directory to server handlers.
static_url = url_path_join("/static", self.extension_name, "(.*)")

# Construct handler.
handler = (static_url, FileFindHandler, {'path': self.static_file_path})
handler = (static_url, FileFindHandler, {'path': self.static_paths})
self.handlers.append(handler)

# Add the file paths to webapp settings.
self.settings.update({
"{}_static_path".format(self.extension_name): self.static_file_path,
"{}_template_path".format(self.extension_name): self.template_path
"{}_static_paths".format(self.extension_name): self.static_paths,
"{}_template_paths".format(self.extension_name): self.template_paths
})

def initialize_handlers(self):
Expand Down Expand Up @@ -147,7 +153,6 @@ def load_jupyter_server_extension(cls, serverapp, argv=None, **kwargs):

# Make extension settings accessible to handlers inside webapp settings.
webapp.settings.update(**extension.settings)
webapp.settings.update(**)

# Add handlers to serverapp.
webapp.add_handlers('.*$', extension.handlers)
Expand Down
14 changes: 12 additions & 2 deletions jupyter_server/extension/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def static_url_prefix(self):

@property
def static_path(self):
return self.settings['{}_static_path'.format(self.extension_name)]
return self.settings['{}_static_paths'.format(self.extension_name)]

def static_url(self, path, include_host=None, **kwargs):
"""Returns a static URL for the given relative static file path.
Expand All @@ -44,7 +44,17 @@ def static_url(self, path, include_host=None, **kwargs):
that value will be used as the default for all `static_url`
calls that do not pass ``include_host`` as a keyword argument.
"""
self.require_setting("{}_static_path".format(self.extension_name), "static_url")
key = "{}_static_paths".format(self.extension_name)
try:
self.require_setting(key, "static_url")
except e:
if key in self.settings:
raise Exception(
"This extension doesn't have any static paths listed. Check that the "
"extension's `static_paths` trait is set."
)
else:
raise e

get_url = self.settings.get(
"static_handler_class", FileFindHandler
Expand Down

0 comments on commit 9217cf9

Please sign in to comment.