##// END OF EJS Templates
add empty metadata field on cells/worksheets...
MinRK -
Show More
@@ -19,6 +19,7 b' var IPython = (function (IPython) {'
19 this.read_only = false;
19 this.read_only = false;
20 this.selected = false;
20 this.selected = false;
21 this.element = null;
21 this.element = null;
22 this.metadata = {};
22 this.create_element();
23 this.create_element();
23 if (this.element !== null) {
24 if (this.element !== null) {
24 this.element.data("cell", this);
25 this.element.data("cell", this);
@@ -90,10 +91,16 b' var IPython = (function (IPython) {'
90
91
91
92
92 Cell.prototype.toJSON = function () {
93 Cell.prototype.toJSON = function () {
94 var data = {};
95 data.metadata = this.metadata;
96 return data;
93 };
97 };
94
98
95
99
96 Cell.prototype.fromJSON = function (data) {
100 Cell.prototype.fromJSON = function (data) {
101 if (data.metadata !== undefined) {
102 this.metadata = data.metadata;
103 }
97 };
104 };
98
105
99
106
@@ -264,6 +264,7 b' var IPython = (function (IPython) {'
264 // JSON serialization
264 // JSON serialization
265
265
266 CodeCell.prototype.fromJSON = function (data) {
266 CodeCell.prototype.fromJSON = function (data) {
267 IPython.Cell.prototype.fromJSON.apply(this, arguments);
267 if (data.cell_type === 'code') {
268 if (data.cell_type === 'code') {
268 if (data.input !== undefined) {
269 if (data.input !== undefined) {
269 this.set_text(data.input);
270 this.set_text(data.input);
@@ -286,7 +287,7 b' var IPython = (function (IPython) {'
286
287
287
288
288 CodeCell.prototype.toJSON = function () {
289 CodeCell.prototype.toJSON = function () {
289 var data = {};
290 var data = IPython.Cell.prototype.toJSON.apply(this);
290 data.input = this.get_text();
291 data.input = this.get_text();
291 data.cell_type = 'code';
292 data.cell_type = 'code';
292 if (this.input_prompt_number) {
293 if (this.input_prompt_number) {
@@ -25,6 +25,8 b' var IPython = (function (IPython) {'
25 this.paste_enabled = false;
25 this.paste_enabled = false;
26 this.dirty = false;
26 this.dirty = false;
27 this.metadata = {};
27 this.metadata = {};
28 // single worksheet for now
29 this.worksheet_metadata = {};
28 this.control_key_active = false;
30 this.control_key_active = false;
29 this.notebook_id = null;
31 this.notebook_id = null;
30 this.notebook_name = null;
32 this.notebook_name = null;
@@ -1003,6 +1005,9 b' var IPython = (function (IPython) {'
1003 // Only handle 1 worksheet for now.
1005 // Only handle 1 worksheet for now.
1004 var worksheet = data.worksheets[0];
1006 var worksheet = data.worksheets[0];
1005 if (worksheet !== undefined) {
1007 if (worksheet !== undefined) {
1008 if (worksheet.metadata) {
1009 this.worksheet_metadata = worksheet.metadata;
1010 }
1006 var new_cells = worksheet.cells;
1011 var new_cells = worksheet.cells;
1007 ncells = new_cells.length;
1012 ncells = new_cells.length;
1008 var cell_data = null;
1013 var cell_data = null;
@@ -1031,7 +1036,10 b' var IPython = (function (IPython) {'
1031 };
1036 };
1032 var data = {
1037 var data = {
1033 // Only handle 1 worksheet for now.
1038 // Only handle 1 worksheet for now.
1034 worksheets : [{cells:cell_array}],
1039 worksheets : [{
1040 cells: cell_array,
1041 metadata: this.worksheet_metadata
1042 }],
1035 metadata : this.metadata
1043 metadata : this.metadata
1036 };
1044 };
1037 return data;
1045 return data;
@@ -155,6 +155,7 b' var IPython = (function (IPython) {'
155
155
156
156
157 TextCell.prototype.fromJSON = function (data) {
157 TextCell.prototype.fromJSON = function (data) {
158 IPython.Cell.prototype.fromJSON.apply(this, arguments);
158 if (data.cell_type === this.cell_type) {
159 if (data.cell_type === this.cell_type) {
159 if (data.source !== undefined) {
160 if (data.source !== undefined) {
160 this.set_text(data.source);
161 this.set_text(data.source);
@@ -167,7 +168,7 b' var IPython = (function (IPython) {'
167
168
168
169
169 TextCell.prototype.toJSON = function () {
170 TextCell.prototype.toJSON = function () {
170 var data = {};
171 var data = IPython.Cell.prototype.toJSON.apply(this);
171 data.cell_type = this.cell_type;
172 data.cell_type = this.cell_type;
172 data.source = this.get_text();
173 data.source = this.get_text();
173 return data;
174 return data;
@@ -92,7 +92,7 b' def new_output(output_type=None, output_text=None, output_png=None,'
92
92
93
93
94 def new_code_cell(input=None, prompt_number=None, outputs=None,
94 def new_code_cell(input=None, prompt_number=None, outputs=None,
95 language=u'python', collapsed=False):
95 language=u'python', collapsed=False, metadata=None):
96 """Create a new code cell with input and output"""
96 """Create a new code cell with input and output"""
97 cell = NotebookNode()
97 cell = NotebookNode()
98 cell.cell_type = u'code'
98 cell.cell_type = u'code'
@@ -108,10 +108,11 b' def new_code_cell(input=None, prompt_number=None, outputs=None,'
108 cell.outputs = outputs
108 cell.outputs = outputs
109 if collapsed is not None:
109 if collapsed is not None:
110 cell.collapsed = bool(collapsed)
110 cell.collapsed = bool(collapsed)
111 cell.metadata = NotebookNode(metadata or {})
111
112
112 return cell
113 return cell
113
114
114 def new_text_cell(cell_type, source=None, rendered=None):
115 def new_text_cell(cell_type, source=None, rendered=None, metadata=None):
115 """Create a new text cell."""
116 """Create a new text cell."""
116 cell = NotebookNode()
117 cell = NotebookNode()
117 # VERSIONHACK: plaintext -> raw
118 # VERSIONHACK: plaintext -> raw
@@ -122,11 +123,12 b' def new_text_cell(cell_type, source=None, rendered=None):'
122 cell.source = unicode(source)
123 cell.source = unicode(source)
123 if rendered is not None:
124 if rendered is not None:
124 cell.rendered = unicode(rendered)
125 cell.rendered = unicode(rendered)
126 cell.metadata = NotebookNode(metadata or {})
125 cell.cell_type = cell_type
127 cell.cell_type = cell_type
126 return cell
128 return cell
127
129
128
130
129 def new_heading_cell(source=None, rendered=None, level=1):
131 def new_heading_cell(source=None, rendered=None, level=1, metadata=None):
130 """Create a new section cell with a given integer level."""
132 """Create a new section cell with a given integer level."""
131 cell = NotebookNode()
133 cell = NotebookNode()
132 cell.cell_type = u'heading'
134 cell.cell_type = u'heading'
@@ -135,10 +137,11 b' def new_heading_cell(source=None, rendered=None, level=1):'
135 if rendered is not None:
137 if rendered is not None:
136 cell.rendered = unicode(rendered)
138 cell.rendered = unicode(rendered)
137 cell.level = int(level)
139 cell.level = int(level)
140 cell.metadata = NotebookNode(metadata or {})
138 return cell
141 return cell
139
142
140
143
141 def new_worksheet(name=None, cells=None):
144 def new_worksheet(name=None, cells=None, metadata=None):
142 """Create a worksheet by name with with a list of cells."""
145 """Create a worksheet by name with with a list of cells."""
143 ws = NotebookNode()
146 ws = NotebookNode()
144 if name is not None:
147 if name is not None:
@@ -147,6 +150,7 b' def new_worksheet(name=None, cells=None):'
147 ws.cells = []
150 ws.cells = []
148 else:
151 else:
149 ws.cells = list(cells)
152 ws.cells = list(cells)
153 ws.metadata = NotebookNode(metadata or {})
150 return ws
154 return ws
151
155
152
156
General Comments 0
You need to be logged in to leave comments. Login now