Index: trunk/extensions/VisualEditor/modules/es/serializers/es.JsonSerializer.js |
— | — | @@ -6,11 +6,13 @@ |
7 | 7 | * @extends {es.Serializer} |
8 | 8 | * @property options {Object} List of options for serialization |
9 | 9 | * @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) |
10 | 11 | */ |
11 | 12 | es.JsonSerializer = function( options ) { |
12 | 13 | es.Serializer.call( this ); |
13 | 14 | this.options = $.extend( { |
14 | | - 'indentWith': '\t' |
| 15 | + 'indentWith': '\t', |
| 16 | + 'joinWith': '\n' |
15 | 17 | }, options || {} ); |
16 | 18 | }; |
17 | 19 | |
— | — | @@ -68,8 +70,8 @@ |
69 | 71 | var comma = false; |
70 | 72 | for ( key in data ) { |
71 | 73 | 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 + '"' + ': ' ); |
74 | 76 | switch ( es.JsonSerializer.typeOf( data[key] ) ) { |
75 | 77 | case 'array': |
76 | 78 | case 'object': |
— | — | @@ -83,9 +85,7 @@ |
84 | 86 | json += 'null'; |
85 | 87 | break; |
86 | 88 | 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') + '"'; |
90 | 90 | break; |
91 | 91 | // Skip other types |
92 | 92 | } |
— | — | @@ -94,7 +94,7 @@ |
95 | 95 | } |
96 | 96 | |
97 | 97 | // Close object/array |
98 | | - json += '\n' + indention + ( type === 'array' ? ']' : '}' ); |
| 98 | + json += this.options.joinWith + indention + ( type === 'array' ? ']' : '}' ); |
99 | 99 | |
100 | 100 | return json; |
101 | 101 | }; |