r99125 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99124‎ | r99125 | r99126 >
Date:18:03, 6 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added references to linear model elements from tree model nodes.
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/bases/es.DocumentModelNode.js (modified) (history)
  • /trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/hype/models/es.ListItemModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/hype/models/es.ListModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/hype/models/es.ParagraphModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/hype/models/es.TableCellModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/hype/models/es.TableModel.js (modified) (history)
  • /trunk/parsers/wikidom/lib/hype/models/es.TableRowModel.js (modified) (history)
  • /trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js
@@ -184,20 +184,20 @@
185185 * This is a node tree that describes each partition within the document's content data.
186186 */
187187 var tree = [
188 - new es.ParagraphModel( 3 ),
189 - new es.TableModel( [
190 - new es.TableRowModel( [
191 - new es.TableCellModel( [
192 - new es.ParagraphModel( 1 ),
193 - new es.ListModel( [
194 - new es.ListItemModel( 1 ),
195 - new es.ListItemModel( 1 ),
196 - new es.ListItemModel( 1 )
 188+ new es.ParagraphModel( data[0], 3 ),
 189+ new es.TableModel( data[5], [
 190+ new es.TableRowModel( data[6], [
 191+ new es.TableCellModel( data[7], [
 192+ new es.ParagraphModel( data[8], 1 ),
 193+ new es.ListModel( data[11], [
 194+ new es.ListItemModel( data[12], 1 ),
 195+ new es.ListItemModel( data[15], 1 ),
 196+ new es.ListItemModel( data[18], 1 )
197197 ] )
198198 ] )
199199 ] )
200200 ] ),
201 - new es.ParagraphModel( 1 )
 201+ new es.ParagraphModel( data[25], 1 )
202202 ];
203203
204204 test( 'es.DocumentModel', function() {
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -11,7 +11,7 @@
1212 */
1313 es.DocumentModel = function( data, attributes ) {
1414 // Inheritance
15 - var node = $.extend( new es.DocumentModelNode( length ), this );
 15+ var node = $.extend( new es.DocumentModelNode( null, length ), this );
1616
1717 // Properties
1818 node.data = $.isArray( data ) ? data : [];
@@ -20,9 +20,10 @@
2121 // Build a tree of models, which is a space partitioning data structure
2222 var currentNode = node;
2323 for ( var i = 0, length = node.data.length; i < length; i++ ) {
24 - if ( node.data[i].type !== undefined ) {
 24+ if ( data[i].type !== undefined ) {
2525 // It's an element, figure out it's type
26 - var type = node.data[i].type,
 26+ var element = node.data[i],
 27+ type = element.type,
2728 open = type[0] !== '/';
2829 // Trim the "/" off the beginning of closing tag types
2930 if ( !open ) {
@@ -34,7 +35,7 @@
3536 throw 'Unsuported element error. No class registered for element type: ' + type;
3637 }
3738 // Create a model node for the element
38 - var newNode = new es.DocumentModel.nodeModels[node.data[i].type]();
 39+ var newNode = new es.DocumentModel.nodeModels[element.type]( element );
3940 // Add the new model node as a child
4041 currentNode.push( newNode );
4142 // Descend into the new model node
@@ -47,7 +48,7 @@
4849 // It's content, let's start tracking the length
4950 var start = i;
5051 // Move forward to the next object, tracking the length as we go
51 - while ( node.data[i].type === undefined && i < length ) {
 52+ while ( data[i].type === undefined && i < length ) {
5253 i++;
5354 }
5455 // Now we know how long the current node is
@@ -57,6 +58,8 @@
5859 }
5960 }
6061
 62+ console.dir( node );
 63+
6164 return node;
6265 };
6366
@@ -174,7 +177,7 @@
175178 }
176179 target.splice( index, 1 );
177180 }
178 - };
 181+ }
179182
180183 return {
181184 // Retain
Index: trunk/parsers/wikidom/lib/hype/models/es.TableRowModel.js
@@ -4,9 +4,9 @@
55 * @class
66 * @constructor
77 */
8 -es.TableRowModel = function( length ) {
 8+es.TableRowModel = function( element, length ) {
99 // Extension
10 - return $.extend( new es.DocumentModelNode( length ), this );
 10+ return $.extend( new es.DocumentModelNode( element, length ), this );
1111 };
1212
1313 /* Methods */
Index: trunk/parsers/wikidom/lib/hype/models/es.ParagraphModel.js
@@ -4,9 +4,9 @@
55 * @class
66 * @constructor
77 */
8 -es.ParagraphModel = function( length ) {
 8+es.ParagraphModel = function( element, length ) {
99 // Extension
10 - return $.extend( new es.DocumentModelNode( length ), this );
 10+ return $.extend( new es.DocumentModelNode( element, length ), this );
1111 };
1212
1313 /* Methods */
Index: trunk/parsers/wikidom/lib/hype/models/es.TableCellModel.js
@@ -4,9 +4,9 @@
55 * @class
66 * @constructor
77 */
8 -es.TableCellModel = function( length ) {
 8+es.TableCellModel = function( element, length ) {
99 // Extension
10 - return $.extend( new es.DocumentModelNode( length ), this );
 10+ return $.extend( new es.DocumentModelNode( element, length ), this );
1111 };
1212
1313 /* Methods */
Index: trunk/parsers/wikidom/lib/hype/models/es.TableModel.js
@@ -4,9 +4,9 @@
55 * @class
66 * @constructor
77 */
8 -es.TableModel = function( length ) {
 8+es.TableModel = function( element, length ) {
99 // Extension
10 - return $.extend( new es.DocumentModelNode( length ), this );
 10+ return $.extend( new es.DocumentModelNode( element, length ), this );
1111 };
1212
1313 /* Methods */
Index: trunk/parsers/wikidom/lib/hype/models/es.ListItemModel.js
@@ -4,9 +4,9 @@
55 * @class
66 * @constructor
77 */
8 -es.ListItemModel = function( length ) {
 8+es.ListItemModel = function( element, length ) {
99 // Extension
10 - return $.extend( new es.DocumentModelNode( length ), this );
 10+ return $.extend( new es.DocumentModelNode( element, length ), this );
1111 };
1212
1313 /* Methods */
Index: trunk/parsers/wikidom/lib/hype/models/es.ListModel.js
@@ -4,9 +4,9 @@
55 * @class
66 * @constructor
77 */
8 -es.ListModel = function( length ) {
 8+es.ListModel = function( element, length ) {
99 // Extension
10 - return $.extend( new es.DocumentModelNode( length ), this );
 10+ return $.extend( new es.DocumentModelNode( element, length ), this );
1111 };
1212
1313 /* Methods */
Index: trunk/parsers/wikidom/lib/hype/bases/es.DocumentModelNode.js
@@ -9,7 +9,7 @@
1010 * @param {Integer|Array} contents Either Length of content or array of child nodes to append
1111 * @property {Integer} contentLength Length of content
1212 */
13 -es.DocumentModelNode = function( contents ) {
 13+es.DocumentModelNode = function( element, contents ) {
1414 // Extension
1515 var node = $.extend( new es.ModelNode(), this );
1616
@@ -23,6 +23,7 @@
2424 } );
2525
2626 // Properties
 27+ node.element = element || null;
2728 node.contentLength = 0;
2829 if ( typeof contents === 'number' ) {
2930 if ( contents < 0 ) {
@@ -129,6 +130,16 @@
130131 };
131132
132133 /**
 134+ * Gets the element object.
 135+ *
 136+ * @method
 137+ * @returns {Object} Element object in linear data model
 138+ */
 139+es.DocumentModelNode.prototype.getElement = function() {
 140+ return this.element;
 141+};
 142+
 143+/**
133144 * Gets the content length.
134145 *
135146 * FIXME: This method makes assumptions that a node with a data property is a DocumentModel, which

Status & tagging log