From c85292cf2e3d8250c237fbff032b9ef10b66069a Mon Sep 17 00:00:00 2001 From: MinRK Date: Wed, 25 Sep 2013 16:24:40 -0700 Subject: [PATCH] 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. --- IPython/html/notebookapp.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py index 955f6df6b..f3216dafe 100644 --- a/IPython/html/notebookapp.py +++ b/IPython/html/notebookapp.py @@ -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)