@@ -154,6 +154,20 @@ Blockly.MicroAlg.scrub_ = function(block, code) {
154154
155155// Commentaire de fin (de section non modifiée).
156156
157+ // https://groups.google.com/forum/#!searchin/blockly/indentation/blockly/siVJ3OQQpQU/lYf6jqdTERMJ
158+ Blockly . Generator . prototype . prefixLines = function ( text , prefix ) {
159+ var splitted = text . split ( '\n' ) ;
160+ if ( splitted . length == 1 ) return prefix + text ;
161+ var indented = splitted . map ( function ( line ) {
162+ console . log ( line ) ;
163+ if ( line . indexOf ( ' Alors' ) == 0 ) return "\n" + line ;
164+ if ( line . indexOf ( ' Sinon' ) == 0 ) return "\n" + line ;
165+ if ( line . indexOf ( ')' ) == 0 ) return "\n" + line ;
166+ return prefix + line ;
167+ } ) ;
168+ return indented . join ( '' ) ;
169+ } ;
170+
157171// Blocs et générateurs (groupés, pas comme dans l’original).
158172// Basés sur:
159173// http://code.google.com/p/blockly/source/browse/trunk/blocks
@@ -577,13 +591,15 @@ Blockly.Blocks['si_alors_sinon_sinon'] = {
577591Blockly . MicroAlg [ 'si' ] = function ( block ) {
578592 var cond = Blockly . MicroAlg . statementToCode ( block , 'COND' ) || '' ;
579593 var branch = Blockly . MicroAlg . statementToCode ( block , 'ALORS' ) || '' ;
594+ branch = branch . replace ( / \) \( / gm, ')\n(' ) ;
580595 var code = '(Si ' + cond . substring ( Blockly . MicroAlg . INDENT . length ) +
581- ' Alors ' + branch . substring ( Blockly . MicroAlg . INDENT . length ) ;
596+ '\n Alors\n ' + Blockly . Generator . prototype . prefixLines ( branch , Blockly . MicroAlg . INDENT ) ;
582597 if ( block . elseCount_ ) {
583- branch = Blockly . MicroAlg . statementToCode ( block , 'SINON' ) || 'pass' ;
584- code += ' Sinon ' + branch ;
598+ branch = Blockly . MicroAlg . statementToCode ( block , 'SINON' ) || '' ;
599+ branch = branch . replace ( / \) \( / gm, ')\n(' ) ;
600+ code += '\n Sinon\n' + Blockly . Generator . prototype . prefixLines ( branch , Blockly . MicroAlg . INDENT ) ;
585601 }
586- code += ')'
602+ code += '\n )'
587603 return code ;
588604} ;
589605
0 commit comments