##// END OF EJS Templates
more docs, organize in namespace
Matthias BUSSONNIER -
Show More
@@ -9,8 +9,10
9 // Cell
9 // Cell
10 //============================================================================
10 //============================================================================
11 /**
11 /**
12 * @module Cell
13 * An extendable module that provide base functionnality to create cell for notebook.
12 * An extendable module that provide base functionnality to create cell for notebook.
13 * @module IPython
14 * @namespace IPython
15 * @submodule Cell
14 */
16 */
15
17
16 var IPython = (function (IPython) {
18 var IPython = (function (IPython) {
@@ -102,28 +104,50 var IPython = (function (IPython) {
102 this.selected = false;
104 this.selected = false;
103 };
105 };
104
106
105
107 /**
108 * should be overritten by subclass
109 * @method get_text
110 */
106 Cell.prototype.get_text = function () {
111 Cell.prototype.get_text = function () {
107 };
112 };
108
113
109
114 /**
115 * should be overritten by subclass
116 * @method set_text
117 * @param {string} text
118 */
110 Cell.prototype.set_text = function (text) {
119 Cell.prototype.set_text = function (text) {
111 };
120 };
112
121
113
122 /**
123 * Refresh codemirror instance
124 * @method refresh
125 */
114 Cell.prototype.refresh = function () {
126 Cell.prototype.refresh = function () {
115 this.code_mirror.refresh();
127 this.code_mirror.refresh();
116 };
128 };
117
129
118
130
131 /**
132 * should be overritten by subclass
133 * @method edit
134 **/
119 Cell.prototype.edit = function () {
135 Cell.prototype.edit = function () {
120 };
136 };
121
137
122
138
139 /**
140 * should be overritten by subclass
141 * @method render
142 **/
123 Cell.prototype.render = function () {
143 Cell.prototype.render = function () {
124 };
144 };
125
145
126
146 /**
147 * should be overritten by subclass
148 * serialise cell to json.
149 * @method toJSON
150 **/
127 Cell.prototype.toJSON = function () {
151 Cell.prototype.toJSON = function () {
128 var data = {};
152 var data = {};
129 data.metadata = this.metadata;
153 data.metadata = this.metadata;
@@ -131,6 +155,10 var IPython = (function (IPython) {
131 };
155 };
132
156
133
157
158 /**
159 * should be overritten by subclass
160 * @method fromJSON
161 **/
134 Cell.prototype.fromJSON = function (data) {
162 Cell.prototype.fromJSON = function (data) {
135 if (data.metadata !== undefined) {
163 if (data.metadata !== undefined) {
136 this.metadata = data.metadata;
164 this.metadata = data.metadata;
@@ -138,11 +166,19 var IPython = (function (IPython) {
138 };
166 };
139
167
140
168
169 /**
170 * can the cell be splitted in 2 cells.
171 * @method is_splittable
172 **/
141 Cell.prototype.is_splittable = function () {
173 Cell.prototype.is_splittable = function () {
142 return true;
174 return true;
143 };
175 };
144
176
145
177
178 /**
179 * @return {String} - the text before the cursor
180 * @method get_pre_cursor
181 **/
146 Cell.prototype.get_pre_cursor = function () {
182 Cell.prototype.get_pre_cursor = function () {
147 var cursor = this.code_mirror.getCursor();
183 var cursor = this.code_mirror.getCursor();
148 var text = this.code_mirror.getRange({line:0,ch:0}, cursor);
184 var text = this.code_mirror.getRange({line:0,ch:0}, cursor);
@@ -151,6 +187,10 var IPython = (function (IPython) {
151 }
187 }
152
188
153
189
190 /**
191 * @return {String} - the text after the cursor
192 * @method get_post_cursor
193 **/
154 Cell.prototype.get_post_cursor = function () {
194 Cell.prototype.get_post_cursor = function () {
155 var cursor = this.code_mirror.getCursor();
195 var cursor = this.code_mirror.getCursor();
156 var last_line_num = this.code_mirror.lineCount()-1;
196 var last_line_num = this.code_mirror.lineCount()-1;
@@ -162,9 +202,15 var IPython = (function (IPython) {
162 };
202 };
163
203
164
204
205 /** Grow the cell by hand. This is used upon reloading from JSON, when the
206 * autogrow handler is not called.
207 *
208 * could be made static
209 *
210 * @param {Dom element} - element
211 * @method grow
212 **/
165 Cell.prototype.grow = function(element) {
213 Cell.prototype.grow = function(element) {
166 // Grow the cell by hand. This is used upon reloading from JSON, when the
167 // autogrow handler is not called.
168 var dom = element.get(0);
214 var dom = element.get(0);
169 var lines_count = 0;
215 var lines_count = 0;
170 // modified split rule from
216 // modified split rule from
@@ -178,7 +224,10 var IPython = (function (IPython) {
178 }
224 }
179 };
225 };
180
226
181
227 /**
228 * Toggle CodeMirror LineNumber
229 * @method toggle_line_numbers
230 **/
182 Cell.prototype.toggle_line_numbers = function () {
231 Cell.prototype.toggle_line_numbers = function () {
183 if (this.code_mirror.getOption('lineNumbers') == false) {
232 if (this.code_mirror.getOption('lineNumbers') == false) {
184 this.code_mirror.setOption('lineNumbers', true);
233 this.code_mirror.setOption('lineNumbers', true);
@@ -188,11 +237,22 var IPython = (function (IPython) {
188 this.code_mirror.refresh();
237 this.code_mirror.refresh();
189 };
238 };
190
239
240 /**
241 * force codemirror highlight mode
242 * @method force_highlight
243 * @param {object} - CodeMirror mode
244 **/
191 Cell.prototype.force_highlight = function(mode) {
245 Cell.prototype.force_highlight = function(mode) {
192 this.user_highlight = mode;
246 this.user_highlight = mode;
193 this.auto_highlight();
247 this.auto_highlight();
194 };
248 };
195
249
250 /**
251 * Try to autodetect cell highlight mode, or use selected mode
252 * @methods _auto_highlight
253 * @private
254 * @param {String|object|undefined} - CodeMirror mode | 'auto'
255 **/
196 Cell.prototype._auto_highlight = function (modes) {
256 Cell.prototype._auto_highlight = function (modes) {
197 //Here we handle manually selected modes
257 //Here we handle manually selected modes
198 if( this.user_highlight != undefined && this.user_highlight != 'auto' )
258 if( this.user_highlight != undefined && this.user_highlight != 'auto' )
@@ -9,9 +9,45
9 // Notebook
9 // Notebook
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 /**
13 * @module IPython
14 * @namespace IPython
15 **/
13
16
17 var IPython = (function (IPython) {
18 /**
19 * A place where some stuff can be confugured.
20 *
21 * @class config
22 * @static
23 *
24 **/
14 var config = {
25 var config = {
26 /**
27 * Dictionary of object to autodetect highlight mode for code cell.
28 * Item of the dictionnary should take the form :
29 *
30 * key : {'reg':[list_of_regexp]}
31 *
32 * where `key` will be the code mirror mode name
33 * and `list_of_regexp` should be a list of regext that should match
34 * the first line of the cell to trigger this mode.
35 *
36 * if `key` is prefixed by the `magic_` prefix the codemirror `mode`
37 * will be applied only at the end of the first line
38 *
39 * @attribute cell_magic_highlight
40 * @example
41 * This would trigger javascript mode
42 * from the second line if first line start with `%%javascript` or `%%jsmagic`
43 *
44 * cell_magic_highlight['magic_javascript'] = {'reg':[/^%%javascript/,/^%%jsmagic/]}
45 * @example
46 * This would trigger javascript mode
47 * from the second line if first line start with `var`
48 *
49 * cell_magic_highlight['javascript'] = {'reg':[/^var/]}
50 */
15 cell_magic_highlight : {
51 cell_magic_highlight : {
16 'magic_javascript':{'reg':[/^%%javascript/]}
52 'magic_javascript':{'reg':[/^%%javascript/]}
17 ,'magic_perl' :{'reg':[/^%%perl/]}
53 ,'magic_perl' :{'reg':[/^%%perl/]}
@@ -20,6 +56,11 var IPython = (function (IPython) {
20 ,'magic_shell' :{'reg':[/^%%bash/]}
56 ,'magic_shell' :{'reg':[/^%%bash/]}
21 ,'magic_r' :{'reg':[/^%%R/]}
57 ,'magic_r' :{'reg':[/^%%R/]}
22 },
58 },
59
60 /**
61 * same as `cell_magic_highlight` but for raw cells
62 * @attribute raw_cell_highlight
63 */
23 raw_cell_highlight : {
64 raw_cell_highlight : {
24 'diff' :{'reg':[/^diff/]}
65 'diff' :{'reg':[/^diff/]}
25 }
66 }
@@ -11,6 +11,8
11
11
12 /**
12 /**
13 A module that allow to create different type of Text Cell
13 A module that allow to create different type of Text Cell
14 @module IPython
15 @namespace IPython
14 */
16 */
15 var IPython = (function (IPython) {
17 var IPython = (function (IPython) {
16
18
General Comments 0
You need to be logged in to leave comments. Login now