r101751 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101750‎ | r101751 | r101752 >
Date:23:34, 2 November 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added joinWith parameter to es.JsonSerializer
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/serializers/es.JsonSerializer.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/serializers/es.JsonSerializer.js
@@ -6,11 +6,13 @@
77 * @extends {es.Serializer}
88 * @property options {Object} List of options for serialization
99 * @property options.indentWith {String} Text to use as indentation, such as \t or 4 spaces
 10+ * @property options.joinWith {String} Text to use as line joiner, such as \n or '' (empty string)
1011 */
1112 es.JsonSerializer = function( options ) {
1213 es.Serializer.call( this );
1314 this.options = $.extend( {
14 - 'indentWith': '\t'
 15+ 'indentWith': '\t',
 16+ 'joinWith': '\n'
1517 }, options || {} );
1618 };
1719
@@ -68,8 +70,8 @@
6971 var comma = false;
7072 for ( key in data ) {
7173 if ( data.hasOwnProperty( key ) ) {
72 - json += ( comma ? ',' : '' ) + '\n' + indention + this.options.indentWith +
73 - ( type === 'array' ? '' : '"' + key + '"' + ': ' );
 74+ json += ( comma ? ',' : '' ) + this.options.joinWith + indention +
 75+ this.options.indentWith + ( type === 'array' ? '' : '"' + key + '"' + ': ' );
7476 switch ( es.JsonSerializer.typeOf( data[key] ) ) {
7577 case 'array':
7678 case 'object':
@@ -83,9 +85,7 @@
8486 json += 'null';
8587 break;
8688 case 'string':
87 - json += '"' + data[key]
88 - .replace(/[\n]/g, '\\n')
89 - .replace(/[\t]/g, '\\t') + '"';
 89+ json += '"' + data[key].replace(/[\n]/g, '\\n').replace(/[\t]/g, '\\t') + '"';
9090 break;
9191 // Skip other types
9292 }
@@ -94,7 +94,7 @@
9595 }
9696
9797 // Close object/array
98 - json += '\n' + indention + ( type === 'array' ? ']' : '}' );
 98+ json += this.options.joinWith + indention + ( type === 'array' ? ']' : '}' );
9999
100100 return json;
101101 };

Status & tagging log