add js_extensions_path

serves files in `IPYTHONDIR/js_extensions` at `/js_extensions`.

This is a location for users / devs to drop-in frontend customization as js modules, css, etc.

The model is very much like the extensions dir (hence the name) - it's a location made available, but not loaded by default. You can load things from there with require, etc.

It's a configurable search path, just like static. This way we can define a system-wide location at a later point (/usr/share/ipython/js_extensions?) and still have user installs.
MinRK 13 years ago
parent 418b44ccff
commit c85292cf2e

@ -85,7 +85,7 @@ from IPython.utils.traitlets import (
DottedObjectName
)
from IPython.utils import py3compat
from IPython.utils.path import filefind
from IPython.utils.path import filefind, get_ipython_dir
from .utils import url_path_join
@ -170,6 +170,7 @@ class NotebookWebApplication(web.Application):
cluster_manager=cluster_manager,
# IPython stuff
js_extensions_path = ipython_app.js_extensions_path,
mathjax_url=ipython_app.mathjax_url,
config=ipython_app.config,
use_less=ipython_app.use_less,
@ -193,6 +194,7 @@ class NotebookWebApplication(web.Application):
handlers.extend(load_handlers('services.clusters.handlers'))
handlers.extend([
(r"/files/(.*)", AuthenticatedFileHandler, {'path' : settings['notebook_manager'].notebook_dir}),
(r"/js_extensions/(.*)", FileFindHandler, {'path' : settings['js_extensions_path']}),
])
# prepend base_project_url onto the patterns that we match
new_handlers = []
@ -432,6 +434,12 @@ class NotebookApp(BaseIPythonApplication):
def static_file_path(self):
"""return extra paths + the default location"""
return self.extra_static_paths + [DEFAULT_STATIC_FILES_PATH]
js_extensions_path = List(Unicode, config=True,
help="""paths for Javascript extensions. By default, this is just IPYTHONDIR/js_extensions"""
)
def _js_extensions_path_default(self):
return [os.path.join(get_ipython_dir(), 'js_extensions')]
mathjax_url = Unicode("", config=True,
help="""The url for MathJax.js."""
@ -521,9 +529,9 @@ class NotebookApp(BaseIPythonApplication):
def init_webapp(self):
"""initialize tornado webapp and httpserver"""
self.web_app = NotebookWebApplication(
self, self.kernel_manager, self.notebook_manager,
self, self.kernel_manager, self.notebook_manager,
self.cluster_manager, self.log,
self.base_project_url, self.webapp_settings
self.base_project_url, self.webapp_settings,
)
if self.certfile:
ssl_options = dict(certfile=self.certfile)

Loading…
Cancel
Save