Bartosz Dziewoński has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/355205 )

Change subject: demos: Fix code generation for more complicated cases
......................................................................

demos: Fix code generation for more complicated cases

This was broken in the last patchset of Ib3f59a68eecc42ca90ce
(https://gerrit.wikimedia.org/r/#/c/353960/18..19/demos/demo.js),
which changed the indentation from 4 spaces to 1 tab, but did
not change the indentation regexp to match tabs instead of spaces.

Also re-add the removal of extra indentation from functions
(e.g. in the TextInputWidget 'validate' config option), now
with a comment to explain the regexp and actually working.

Bug: T165457
Change-Id: I386d477438e6b2dfc0a811704da32b142a9dc6be
---
M demos/demo.js
1 file changed, 6 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/05/355205/1

diff --git a/demos/demo.js b/demos/demo.js
index 24d1377..072b360 100644
--- a/demos/demo.js
+++ b/demos/demo.js
@@ -545,12 +545,13 @@
                // as a string and won't do proper indentation either
                replaceLater.forEach( function ( obj, i ) {
                        config = config.replace(
-                               // Match any number of spaces (for indentation) 
followed by our placeholder
-                               new RegExp( '([ ]+)"' + replaceKeyword + i + 
'"' ),
-                               function ( all, indent ) {
+                               // Match any number of tabs (for indentation) 
and optional object key, followed by our placeholder
+                               new RegExp( '(\t*)("[^"]+?": |)"' + 
replaceKeyword + i + '"' ),
+                               function ( all, indent, objectKey ) {
                                        var code;
                                        if ( obj instanceof Function ) {
-                                               code = obj.toString();
+                                               // Get function's source code, 
with extraneous indentation removed
+                                               code = obj.toString().replace( 
/^\t\t\t\t\t\t/gm, '' );
                                        } else if ( obj instanceof jQuery ) {
                                                if ( $.contains( item.$element[ 
0 ], obj[ 0 ] ) ) {
                                                        // If this element 
appears inside the generated widget,
@@ -566,7 +567,7 @@
                                                code = getCode( obj );
                                        }
                                        // Re-add the indent at the beginning, 
and after every newline
-                                       return indent + code.replace( /\n/g, 
'\n' + indent );
+                                       return indent + objectKey + 
code.replace( /\n/g, '\n' + indent );
                                }
                        );
                } );

-- 
To view, visit https://gerrit.wikimedia.org/r/355205
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I386d477438e6b2dfc0a811704da32b142a9dc6be
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to