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