From 43da311f5ee563470c898145b8f765998b59aaec Mon Sep 17 00:00:00 2001 From: Min RK Date: Mon, 22 Dec 2014 13:21:14 -0800 Subject: [PATCH] add Notebook.ensure_extension allows override of file-extension logic in notebook extensions --- IPython/html/static/notebook/js/notebook.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 94be416de..3a6d014a3 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -2031,6 +2031,17 @@ define([ } ); }; + + /** + * Ensure a filename has the right extension + * Returns the filename with the appropriate extension, appending if necessary. + */ + Notebook.prototype.ensure_extension = function (name) { + if (!name.match(/\.ipynb$/)) { + name = name + ".ipynb"; + } + return name; + }; /** * Rename the notebook. @@ -2038,9 +2049,7 @@ define([ * @return {Promise} promise that resolves when the notebook is renamed. */ Notebook.prototype.rename = function (new_name) { - if (!new_name.match(/\.ipynb$/)) { - new_name = new_name + ".ipynb"; - } + new_name = this.ensure_extension(new_name); var that = this; var parent = utils.url_path_split(this.notebook_path)[0];