From cd1304961f6cf20670081a28235ab2a572c6cc7a Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Wed, 5 Nov 2014 00:19:17 -0500 Subject: [PATCH 1/3] DEV: Support for configurable list of extra jinja template directories. --- IPython/html/__init__.py | 4 +++- IPython/html/notebookapp.py | 25 ++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/IPython/html/__init__.py b/IPython/html/__init__.py index 97e2c984b..b250a9620 100644 --- a/IPython/html/__init__.py +++ b/IPython/html/__init__.py @@ -3,7 +3,9 @@ import os # Packagers: modify this line if you store the notebook static files elsewhere DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "static") +# Packagers: modify this line if you store the notebook template files elsewhere +DEFAULT_TEMPLATE_FILES_PATH = os.path.join(os.path.dirname(__file__), "templates") del os -from .nbextensions import install_nbextension \ No newline at end of file +from .nbextensions import install_nbextension diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py index bf7f4f8d5..0f73ca895 100644 --- a/IPython/html/notebookapp.py +++ b/IPython/html/notebookapp.py @@ -51,7 +51,10 @@ from tornado import httpserver from tornado import web from tornado.log import LogFormatter, app_log, access_log, gen_log -from IPython.html import DEFAULT_STATIC_FILES_PATH +from IPython.html import ( + DEFAULT_STATIC_FILES_PATH, + DEFAULT_TEMPLATE_FILES_PATH, +) from .base.handlers import Template404 from .log import log_request from .services.kernels.kernelmanager import MappingKernelManager @@ -138,7 +141,10 @@ class NotebookWebApplication(web.Application): log, base_url, default_url, settings_overrides, jinja_env_options=None): - _template_path = settings_overrides.get("template_path", os.path.join(os.path.dirname(__file__), "templates")) + _template_path = settings_overrides.get( + "template_path", + ipython_app.template_file_path, + ) if isinstance(_template_path, str): _template_path = (_template_path,) template_path = [os.path.expanduser(path) for path in _template_path] @@ -519,7 +525,20 @@ class NotebookApp(BaseIPythonApplication): def static_file_path(self): """return extra paths + the default location""" return self.extra_static_paths + [DEFAULT_STATIC_FILES_PATH] - + + extra_template_paths = List(Unicode, config=True, + help="""Extra paths to search for serving jinja templates. + + Can be used to override templates from IPython.html.templates.""" + ) + def _extra_template_paths_default(self): + return [] + + @property + def template_file_path(self): + """return extra paths + the default location""" + return self.extra_template_paths + [DEFAULT_TEMPLATE_FILES_PATH] + nbextensions_path = List(Unicode, config=True, help="""paths for Javascript extensions. By default, this is just IPYTHONDIR/nbextensions""" ) From c1196da096f63a39786ab3bbadb16bb842898108 Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Wed, 5 Nov 2014 13:29:31 -0500 Subject: [PATCH 2/3] DEV: Add IPython.html to the default template path. This makes it possible to override a file with a template that also inherits from that file. For example, this makes it possible to override a single block of notebook.html by creating a file called notebook.html that inherits from templates/notebook.html. --- IPython/html/__init__.py | 18 ++++++++++++++++-- IPython/html/notebookapp.py | 6 +++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/IPython/html/__init__.py b/IPython/html/__init__.py index b250a9620..d318d671e 100644 --- a/IPython/html/__init__.py +++ b/IPython/html/__init__.py @@ -3,8 +3,22 @@ import os # Packagers: modify this line if you store the notebook static files elsewhere DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "static") -# Packagers: modify this line if you store the notebook template files elsewhere -DEFAULT_TEMPLATE_FILES_PATH = os.path.join(os.path.dirname(__file__), "templates") + +# Packagers: modify the next line if you store the notebook template files +# elsewhere + +# Include both IPython/html/ and IPython/html/templates/. This makes it +# possible for users to override a template with a file that inherits from that +# template. +# +# For example, if you want to override a specific block of notebook.html, you +# can create a file called notebook.html that inherits from from +# templates/notebook.html, and the latter will resolve correctly to the base +# implementation. +DEFAULT_TEMPLATE_PATH_LIST = [ + os.path.dirname(__file__), + os.path.join(os.path.dirname(__file__), "templates"), +] del os diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py index 0f73ca895..b6b41bb53 100644 --- a/IPython/html/notebookapp.py +++ b/IPython/html/notebookapp.py @@ -53,7 +53,7 @@ from tornado.log import LogFormatter, app_log, access_log, gen_log from IPython.html import ( DEFAULT_STATIC_FILES_PATH, - DEFAULT_TEMPLATE_FILES_PATH, + DEFAULT_TEMPLATE_PATH_LIST, ) from .base.handlers import Template404 from .log import log_request @@ -536,8 +536,8 @@ class NotebookApp(BaseIPythonApplication): @property def template_file_path(self): - """return extra paths + the default location""" - return self.extra_template_paths + [DEFAULT_TEMPLATE_FILES_PATH] + """return extra paths + the default locations""" + return self.extra_template_paths + DEFAULT_TEMPLATE_PATH_LIST nbextensions_path = List(Unicode, config=True, help="""paths for Javascript extensions. By default, this is just IPYTHONDIR/nbextensions""" From 8a6af683cee1f5038297b4f54ce3fbcd65b6e7c7 Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Thu, 6 Nov 2014 14:59:44 -0500 Subject: [PATCH 3/3] DOC: Fix typo in comment. --- IPython/html/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IPython/html/__init__.py b/IPython/html/__init__.py index d318d671e..a58d48267 100644 --- a/IPython/html/__init__.py +++ b/IPython/html/__init__.py @@ -12,7 +12,7 @@ DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "static") # template. # # For example, if you want to override a specific block of notebook.html, you -# can create a file called notebook.html that inherits from from +# can create a file called notebook.html that inherits from # templates/notebook.html, and the latter will resolve correctly to the base # implementation. DEFAULT_TEMPLATE_PATH_LIST = [