r98587 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98586‎ | r98587 | r98588 >
Date:00:10, 1 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Removed document elements from es.DocumentModel data.
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.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
@@ -120,8 +120,6 @@
121121 */
122122 var data = [
123123 // 0 - Beginning of paragraph
124 - { 'type': 'document' },
125 - // 0 - Beginning of paragraph
126124 { 'type': 'paragraph' },
127125 // 1 - Plain content
128126 'a',
@@ -176,9 +174,7 @@
177175 // 26 - Plain content
178176 'a',
179177 // 27 - End of paragraph
180 - { 'type': '/paragraph' },
181 - // 27 - End of paragraph
182 - { 'type': '/document' }
 178+ { 'type': '/paragraph' }
183179 ];
184180
185181 test( 'es.ModelNode', function() {
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -7,12 +7,15 @@
88 * @class
99 * @constructor
1010 * @param {Array} data Model data to initialize with, such as data from es.DocumentModel.getData()
 11+ * @param {Object} attributes Document attributes
1112 */
12 -es.DocumentModel = function( data ) {
 13+es.DocumentModel = function( data, attributes ) {
1314 // Inheritance
1415 es.DocumentModelNode.call( this, length );
1516
 17+ // Properties
1618 this.data = $.isArray( data ) ? data : [];
 19+ this.attributes = $.isPlainObject( attributes ) ? attributes : {};
1720 };
1821
1922 /* Static Methods */
@@ -51,10 +54,17 @@
5255 * @returns {es.DocumentModel} Document model created from obj
5356 */
5457 es.DocumentModel.newFromPlainObject = function( obj ) {
55 - return new es.DocumentModel( es.DocumentModel.flattenPlainObjectElementNode( obj ) );
 58+ if ( obj.type === 'document' ) {
 59+ var data = [],
 60+ attributes = $.isPlainObject( obj.attributes ) ? es.copyObject( obj.attributes ) : {};
 61+ for ( var i = 0; i < obj.children.length; i++ ) {
 62+ data = data.concat( es.DocumentModel.flattenPlainObjectElementNode( obj.children[i] ) );
 63+ }
 64+ return new es.DocumentModel( data, attributes );
 65+ }
 66+ throw 'Invalid object error. Object is not a valid document object.';
5667 };
5768
58 -
5969 /**
6070 * Creates an es.ContentModel object from a plain content object.
6171 *

Status & tagging log