ipython/ipython — pull request #7083 by takluyver (2014-12-02 23:56:57+00:00)
Title: Add support for notebook server extensions

As some people may be tiring of my pointing out, it seems strange that we have extension points for the JS and the kernel, but none for the notebook server.

For cite2c, I want to add a handler which can serve a directory of style files for use by the nbextension part. With this PR, the extension for that looks like this:

```python
from IPython.html.utils import url_path_join as ujoin
from tornado.web import StaticFileHandler

def load_jupyter_server_extension(nbapp):
webapp = nbapp.web_app
base_url = webapp.settings['base_url']
webapp.add_handlers(".*$", [
(ujoin(base_url, r"/cite2c/styles/(.*)"), StaticFileHandler, {'path': '...'})
])
```

Like our other extension APIs, the extension may define a single function, here `load_jupyter_server_extension()`, which we will call with a reference to the notebookapplication object. From that object you can access just about anything else of interest in the notebook application.

If adding handlers is a common use case, we may want to add a convenience method that does so correctly, taking account of base_url.