##// END OF EJS Templates
Remove user_config js module
Thomas Kluyver -
Show More
@@ -14,6 +14,7 b' define(['
14 'jquery',
14 'jquery',
15 'base/js/utils',
15 'base/js/utils',
16 'base/js/keyboard',
16 'base/js/keyboard',
17 'services/config',
17 'notebook/js/cell',
18 'notebook/js/cell',
18 'notebook/js/outputarea',
19 'notebook/js/outputarea',
19 'notebook/js/completer',
20 'notebook/js/completer',
@@ -21,7 +22,19 b' define(['
21 'codemirror/lib/codemirror',
22 'codemirror/lib/codemirror',
22 'codemirror/mode/python/python',
23 'codemirror/mode/python/python',
23 'notebook/js/codemirror-ipython'
24 'notebook/js/codemirror-ipython'
24 ], function(IPython, $, utils, keyboard, cell, outputarea, completer, celltoolbar, CodeMirror, cmpython, cmip) {
25 ], function(IPython,
26 $,
27 utils,
28 keyboard,
29 configmod,
30 cell,
31 outputarea,
32 completer,
33 celltoolbar,
34 CodeMirror,
35 cmpython,
36 cmip
37 ) {
25 "use strict";
38 "use strict";
26
39
27 var Cell = cell.Cell;
40 var Cell = cell.Cell;
@@ -76,6 +89,8 b' define(['
76 this.events = options.events;
89 this.events = options.events;
77 this.tooltip = options.tooltip;
90 this.tooltip = options.tooltip;
78 this.config = options.config;
91 this.config = options.config;
92 this.class_config = new configmod.ConfigWithDefaults(this.config,
93 CodeCell.config_defaults, 'CodeCell');
79
94
80 // create all attributed in constructor function
95 // create all attributed in constructor function
81 // even if null for V8 VM optimisation
96 // even if null for V8 VM optimisation
@@ -103,9 +118,8 b' define(['
103 this.completer = null;
118 this.completer = null;
104 this.widget_views = [];
119 this.widget_views = [];
105
120
106 var config = utils.mergeopt(CodeCell, this.config);
107 Cell.apply(this,[{
121 Cell.apply(this,[{
108 config: config,
122 config: $.extend({}, CodeCell.options_default),
109 keyboard_manager: options.keyboard_manager,
123 keyboard_manager: options.keyboard_manager,
110 events: this.events}]);
124 events: this.events}]);
111
125
@@ -131,6 +145,18 b' define(['
131 }
145 }
132 };
146 };
133
147
148 CodeCell.config_defaults = {
149 cell_magic_highlight : {
150 'magic_javascript' :{'reg':[/^%%javascript/]},
151 'magic_perl' :{'reg':[/^%%perl/]},
152 'magic_ruby' :{'reg':[/^%%ruby/]},
153 'magic_python' :{'reg':[/^%%python3?/]},
154 'magic_shell' :{'reg':[/^%%bash/]},
155 'magic_r' :{'reg':[/^%%R/]},
156 'magic_text/x-cython' :{'reg':[/^%%cython/]},
157 },
158 };
159
134 CodeCell.msg_cells = {};
160 CodeCell.msg_cells = {};
135
161
136 CodeCell.prototype = Object.create(Cell.prototype);
162 CodeCell.prototype = Object.create(Cell.prototype);
@@ -156,7 +182,7 b' define(['
156 * @method auto_highlight
182 * @method auto_highlight
157 */
183 */
158 CodeCell.prototype.auto_highlight = function () {
184 CodeCell.prototype.auto_highlight = function () {
159 this._auto_highlight(this.config.cell_magic_highlight);
185 this._auto_highlight(this.class_config.get_sync('cell_magic_highlight'));
160 };
186 };
161
187
162 /** @method create_element */
188 /** @method create_element */
@@ -19,7 +19,6 b' require(['
19 'notebook/js/savewidget',
19 'notebook/js/savewidget',
20 'notebook/js/actions',
20 'notebook/js/actions',
21 'notebook/js/keyboardmanager',
21 'notebook/js/keyboardmanager',
22 'notebook/js/config',
23 'notebook/js/kernelselector',
22 'notebook/js/kernelselector',
24 'codemirror/lib/codemirror',
23 'codemirror/lib/codemirror',
25 'notebook/js/about',
24 'notebook/js/about',
@@ -43,7 +42,6 b' require(['
43 savewidget,
42 savewidget,
44 actions,
43 actions,
45 keyboardmanager,
44 keyboardmanager,
46 config,
47 kernelselector,
45 kernelselector,
48 CodeMirror,
46 CodeMirror,
49 about,
47 about,
@@ -62,7 +60,6 b' require(['
62 notebook_name : utils.get_body_data('notebookName')
60 notebook_name : utils.get_body_data('notebookName')
63 };
61 };
64
62
65 var user_config = $.extend({}, config.default_config);
66 var page = new page.Page();
63 var page = new page.Page();
67 var pager = new pager.Pager('div#pager', {
64 var pager = new pager.Pager('div#pager', {
68 events: events});
65 events: events});
@@ -84,7 +81,7 b' require(['
84 keyboard_manager: keyboard_manager,
81 keyboard_manager: keyboard_manager,
85 save_widget: save_widget,
82 save_widget: save_widget,
86 contents: contents,
83 contents: contents,
87 config: user_config},
84 config: config_section},
88 common_options));
85 common_options));
89 var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options);
86 var login_widget = new loginwidget.LoginWidget('span#login_widget', common_options);
90 var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', {
87 var toolbar = new maintoolbar.MainToolBar('#maintoolbar-container', {
@@ -150,7 +147,6 b' require(['
150 IPython.notification_area = notification_area;
147 IPython.notification_area = notification_area;
151 IPython.keyboard_manager = keyboard_manager;
148 IPython.keyboard_manager = keyboard_manager;
152 IPython.save_widget = save_widget;
149 IPython.save_widget = save_widget;
153 IPython.config = user_config;
154 IPython.tooltip = notebook.tooltip;
150 IPython.tooltip = notebook.tooltip;
155
151
156 events.trigger('app_initialized.NotebookApp');
152 events.trigger('app_initialized.NotebookApp');
@@ -12,6 +12,7 b' define(['
12 'notebook/js/cell',
12 'notebook/js/cell',
13 'notebook/js/textcell',
13 'notebook/js/textcell',
14 'notebook/js/codecell',
14 'notebook/js/codecell',
15 'services/config',
15 'services/sessions/session',
16 'services/sessions/session',
16 'notebook/js/celltoolbar',
17 'notebook/js/celltoolbar',
17 'components/marked/lib/marked',
18 'components/marked/lib/marked',
@@ -32,6 +33,7 b' define(['
32 cellmod,
33 cellmod,
33 textcell,
34 textcell,
34 codecell,
35 codecell,
36 configmod,
35 session,
37 session,
36 celltoolbar,
38 celltoolbar,
37 marked,
39 marked,
@@ -63,7 +65,9 b' define(['
63 * @param {string} options.notebook_name
65 * @param {string} options.notebook_name
64 */
66 */
65 var Notebook = function (selector, options) {
67 var Notebook = function (selector, options) {
66 this.config = utils.mergeopt(Notebook, options.config);
68 this.config = options.config;
69 this.class_config = new configmod.ConfigWithDefaults(this.config,
70 Notebook.options_default, 'Notebook');
67 this.base_url = options.base_url;
71 this.base_url = options.base_url;
68 this.notebook_path = options.notebook_path;
72 this.notebook_path = options.notebook_path;
69 this.notebook_name = options.notebook_name;
73 this.notebook_name = options.notebook_name;
@@ -74,7 +78,6 b' define(['
74 this.tooltip = new tooltip.Tooltip(this.events);
78 this.tooltip = new tooltip.Tooltip(this.events);
75 this.ws_url = options.ws_url;
79 this.ws_url = options.ws_url;
76 this._session_starting = false;
80 this._session_starting = false;
77 this.default_cell_type = this.config.default_cell_type || 'code';
78
81
79 // Create default scroll manager.
82 // Create default scroll manager.
80 this.scroll_manager = new scrollmanager.ScrollManager(this);
83 this.scroll_manager = new scrollmanager.ScrollManager(this);
@@ -861,7 +864,7 b' define(['
861 index = Math.min(index, ncells);
864 index = Math.min(index, ncells);
862 index = Math.max(index, 0);
865 index = Math.max(index, 0);
863 var cell = null;
866 var cell = null;
864 type = type || this.default_cell_type;
867 type = type || this.class_config.get_sync('default_cell_type');
865 if (type === 'above') {
868 if (type === 'above') {
866 if (index > 0) {
869 if (index > 0) {
867 type = this.get_cell(index-1).cell_type;
870 type = this.get_cell(index-1).cell_type;
@@ -7,13 +7,26 b' define(['
7 'jquery',
7 'jquery',
8 'notebook/js/cell',
8 'notebook/js/cell',
9 'base/js/security',
9 'base/js/security',
10 'services/config',
10 'notebook/js/mathjaxutils',
11 'notebook/js/mathjaxutils',
11 'notebook/js/celltoolbar',
12 'notebook/js/celltoolbar',
12 'components/marked/lib/marked',
13 'components/marked/lib/marked',
13 'codemirror/lib/codemirror',
14 'codemirror/lib/codemirror',
14 'codemirror/mode/gfm/gfm',
15 'codemirror/mode/gfm/gfm',
15 'notebook/js/codemirror-ipythongfm'
16 'notebook/js/codemirror-ipythongfm'
16 ], function(IPython,utils , $, cell, security, mathjaxutils, celltoolbar, marked, CodeMirror, gfm, ipgfm) {
17 ], function(IPython,
18 utils,
19 $,
20 cell,
21 security,
22 configmod,
23 mathjaxutils,
24 celltoolbar,
25 marked,
26 CodeMirror,
27 gfm,
28 ipgfm
29 ) {
17 "use strict";
30 "use strict";
18 var Cell = cell.Cell;
31 var Cell = cell.Cell;
19
32
@@ -204,14 +217,16 b' define(['
204 * options: dictionary
217 * options: dictionary
205 * Dictionary of keyword arguments.
218 * Dictionary of keyword arguments.
206 * events: $(Events) instance
219 * events: $(Events) instance
207 * config: dictionary
220 * config: ConfigSection instance
208 * keyboard_manager: KeyboardManager instance
221 * keyboard_manager: KeyboardManager instance
209 * notebook: Notebook instance
222 * notebook: Notebook instance
210 */
223 */
211 options = options || {};
224 options = options || {};
212 var config = utils.mergeopt(MarkdownCell, options.config);
225 var config = utils.mergeopt(MarkdownCell, {});
213 TextCell.apply(this, [$.extend({}, options, {config: config})]);
226 TextCell.apply(this, [$.extend({}, options, {config: config})]);
214
227
228 this.class_config = new configmod.ConfigWithDefaults(options.config,
229 {}, 'MarkdownCell');
215 this.cell_type = 'markdown';
230 this.cell_type = 'markdown';
216 };
231 };
217
232
@@ -287,14 +302,16 b' define(['
287 * options: dictionary
302 * options: dictionary
288 * Dictionary of keyword arguments.
303 * Dictionary of keyword arguments.
289 * events: $(Events) instance
304 * events: $(Events) instance
290 * config: dictionary
305 * config: ConfigSection instance
291 * keyboard_manager: KeyboardManager instance
306 * keyboard_manager: KeyboardManager instance
292 * notebook: Notebook instance
307 * notebook: Notebook instance
293 */
308 */
294 options = options || {};
309 options = options || {};
295 var config = utils.mergeopt(RawCell, options.config);
310 var config = utils.mergeopt(RawCell, {});
296 TextCell.apply(this, [$.extend({}, options, {config: config})]);
311 TextCell.apply(this, [$.extend({}, options, {config: config})]);
297
312
313 this.class_config = new configmod.ConfigWithDefaults(options.config,
314 RawCell.config_defaults, 'RawCell');
298 this.cell_type = 'raw';
315 this.cell_type = 'raw';
299 };
316 };
300
317
@@ -303,6 +320,12 b' define(['
303 "It will not be rendered in the notebook. " +
320 "It will not be rendered in the notebook. " +
304 "When passing through nbconvert, a Raw Cell's content is added to the output unmodified."
321 "When passing through nbconvert, a Raw Cell's content is added to the output unmodified."
305 };
322 };
323
324 RawCell.config_defaults = {
325 highlight_modes : {
326 'diff' :{'reg':[/^diff/]}
327 },
328 };
306
329
307 RawCell.prototype = Object.create(TextCell.prototype);
330 RawCell.prototype = Object.create(TextCell.prototype);
308
331
@@ -323,7 +346,7 b' define(['
323 * @method auto_highlight
346 * @method auto_highlight
324 */
347 */
325 RawCell.prototype.auto_highlight = function () {
348 RawCell.prototype.auto_highlight = function () {
326 this._auto_highlight(this.config.raw_cell_highlight);
349 this._auto_highlight(this.class_config.get_sync('highlight_modes'));
327 };
350 };
328
351
329 /** @method render **/
352 /** @method render **/
@@ -63,6 +63,42 b' function($, utils) {'
63 });
63 });
64 };
64 };
65
65
66 return {ConfigSection: ConfigSection};
66
67 var ConfigWithDefaults = function(section, defaults, classname) {
68 this.section = section;
69 this.defaults = defaults;
70 this.classname = classname;
71 };
72
73 ConfigWithDefaults.prototype._class_data = function() {
74 if (this.classname) {
75 return this.section.data[this.classname] || {};
76 } else {
77 return this.section.data
78 }
79 };
80
81 /**
82 * Wait for config to have loaded, then get a value or the default.
83 * Returns a promise.
84 */
85 ConfigWithDefaults.prototype.get = function(key) {
86 var that = this;
87 return this.section.loaded.then(function() {
88 return this._class_data()[key] || this.defaults[key]
89 });
90 };
91
92 /**
93 * Return a config value. If config is not yet loaded, return the default
94 * instead of waiting for it to load.
95 */
96 ConfigWithDefaults.prototype.get_sync = function(key) {
97 return this._class_data()[key] || this.defaults[key];
98 };
99
100 return {ConfigSection: ConfigSection,
101 ConfigWithDefaults: ConfigWithDefaults,
102 };
67
103
68 });
104 });
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now