@@ -46,7 +46,7 @@ export default function (Blockly) {
4646 Blockly . Ruby . ORDER_NONE = 99 ;
4747 Blockly . Ruby . INFINITE_LOOP_TRAP = null ;
4848
49- Blockly . Ruby . init = function ( ) {
49+ Blockly . Ruby . init = function ( ) {
5050 this . definitions_ = Object . create ( null ) ;
5151 this . targetEventBlock = null ;
5252 if ( Blockly . Variables ) {
@@ -55,69 +55,69 @@ export default function (Blockly) {
5555 } else {
5656 this . variableDB_ . reset ( ) ;
5757 }
58- //this.definitions_['require__smalruby'] = 'require "smalruby"';
59- this . definitions_ [ ' receiver_stack' ] = [ 'main' ] ;
60- return this . definitions_ [ ' character_stack' ] = [ ] ;
58+ // this.definitions_['require__smalruby'] = 'require "smalruby"';
59+ this . definitions_ . receiver_stack = [ 'main' ] ;
60+ return this . definitions_ . character_stack = [ ] ;
6161 }
6262 } ;
6363
64- Blockly . Ruby . defineCharacter = function ( c ) {
65- var blockName , costume , costumeIndex , costumeParam , costumes , name , rotationStyle ;
64+ Blockly . Ruby . defineCharacter = function ( c ) {
65+ let blockName ; let costume ; let costumeIndex ; let costumeParam ; let costumes ; let name ; let rotationStyle ;
6666 name = c . get ( 'name' ) ;
67- blockName = " character_" + name ;
67+ blockName = ` character_${ name } ` ;
6868 if ( ! Blockly . Ruby . definitions_ [ blockName ] ) {
6969 switch ( c . get ( 'rotationStyle' ) ) {
70- case 'left_right' :
71- rotationStyle = ', rotation_style: :left_right' ;
72- break ;
73- case 'none' :
74- rotationStyle = ', rotation_style: :none' ;
75- break ;
76- default :
77- rotationStyle = '' ;
70+ case 'left_right' :
71+ rotationStyle = ', rotation_style: :left_right' ;
72+ break ;
73+ case 'none' :
74+ rotationStyle = ', rotation_style: :none' ;
75+ break ;
76+ default :
77+ rotationStyle = '' ;
7878 }
7979 costumeParam = [ 'costume: ' ] ;
80- costumes = ( function ( ) {
81- var _i , _len , _ref , _results ;
80+ costumes = ( function ( ) {
81+ let _i ; let _len ; let _ref ; let _results ;
8282 _ref = c . costumesWithName ( ) ;
8383 _results = [ ] ;
8484 for ( _i = 0 , _len = _ref . length ; _i < _len ; _i ++ ) {
8585 costume = _ref [ _i ] ;
8686 _results . push ( Blockly . Ruby . quote_ ( costume ) ) ;
8787 }
8888 return _results ;
89- } ) ( ) ;
89+ } ( ) ) ;
9090 if ( costumes . length > 1 ) {
91- costumeParam . push ( "[" + ( costumes . join ( ', ' ) ) + "]" ) ;
91+ costumeParam . push ( `[ ${ costumes . join ( ', ' ) } ]` ) ;
9292 } else {
9393 costumeParam . push ( costumes [ 0 ] ) ;
9494 }
9595 costumeIndex = c . get ( 'costumeIndex' ) ;
9696 if ( costumeIndex > 0 ) {
97- costumeParam . push ( " , costume_index: " + costumeIndex ) ;
97+ costumeParam . push ( ` , costume_index: ${ costumeIndex } ` ) ;
9898 }
99- return Blockly . Ruby . definitions_ [ blockName ] = name + " = Character.new(" + ( costumeParam . join ( '' ) ) + " , x: " + ( c . get ( 'x' ) ) + " , y: " + ( c . get ( 'y' ) ) + " , angle: " + ( c . get ( 'angle' ) ) + rotationStyle + ")" ;
99+ return Blockly . Ruby . definitions_ [ blockName ] = ` ${ name } = Character.new(${ costumeParam . join ( '' ) } , x: ${ c . get ( 'x' ) } , y: ${ c . get ( 'y' ) } , angle: ${ c . get ( 'angle' ) } ${ rotationStyle } )` ;
100100 }
101101 } ;
102102
103- Blockly . Ruby . characterStack = function ( ) {
104- return this . definitions_ [ ' character_stack' ] ;
103+ Blockly . Ruby . characterStack = function ( ) {
104+ return this . definitions_ . character_stack ;
105105 } ;
106106
107- Blockly . Ruby . character = function ( ) {
107+ Blockly . Ruby . character = function ( ) {
108108 return _ . last ( this . characterStack ( ) ) ;
109109 } ;
110110
111- Blockly . Ruby . receiverStack = function ( ) {
112- return this . definitions_ [ ' receiver_stack' ] ;
111+ Blockly . Ruby . receiverStack = function ( ) {
112+ return this . definitions_ . receiver_stack ;
113113 } ;
114114
115- Blockly . Ruby . receiver = function ( ) {
115+ Blockly . Ruby . receiver = function ( ) {
116116 return _ . last ( this . receiverStack ( ) ) ;
117117 } ;
118118
119- Blockly . Ruby . receiverName = function ( options ) {
120- var opts , r ;
119+ Blockly . Ruby . receiverName = function ( options ) {
120+ let opts ; let r ;
121121 if ( options == null ) {
122122 options = { } ;
123123 }
@@ -130,12 +130,10 @@ export default function (Blockly) {
130130 if ( r === opts . object ) {
131131 if ( opts . dropSelf ) {
132132 return '' ;
133- } else {
134- return 'self.' ;
135133 }
136- } else {
137- return ( opts . object . get ( 'name' ) ) + "." ;
134+ return 'self.' ;
138135 }
136+ return `${ opts . object . get ( 'name' ) } .` ;
139137 } ;
140138
141139 Blockly . Ruby . cs = Blockly . Ruby . characterStack ;
@@ -158,43 +156,41 @@ export default function (Blockly) {
158156
159157 Blockly . Ruby . rn_ = Blockly . Ruby . receiverName ;
160158
161- Blockly . Ruby . characterMethodCall_ = function ( method , args , options ) {
162- var res ;
159+ Blockly . Ruby . characterMethodCall_ = function ( method , args , options ) {
160+ let res ;
163161 if ( options == null ) {
164162 options = { } ;
165163 }
166164 res = this . characterMethodCallInput_ ( method , args , options ) ;
167165 if ( res [ 0 ] ) {
168- return res [ 0 ] + "\n" ;
169- } else {
170- return '' ;
166+ return `${ res [ 0 ] } \n` ;
171167 }
168+ return '' ;
172169 } ;
173170
174- Blockly . Ruby . characterMethodCallInput_ = function ( method , args , options ) {
175- var code ;
171+ Blockly . Ruby . characterMethodCallInput_ = function ( method , args , options ) {
172+ let code ;
176173 if ( options == null ) {
177174 options = { } ;
178175 }
179- code = this . c_ ( ) ? args && args . length > 0 ? "" + ( this . rn_ ( options ) ) + method + "(" + args + ")" : "" + ( this . rn_ ( options ) ) + method : null ;
176+ code = this . c_ ( ) ? args && args . length > 0 ? ` ${ this . rn_ ( options ) } ${ method } ( ${ args } )` : ` ${ this . rn_ ( options ) } ${ method } ` : null ;
180177 return [ code , this . ORDER_FUNCTION_CALL ] ;
181178 } ;
182179
183- Blockly . Ruby . characterSetVariable_ = function ( name , val , operator ) {
180+ Blockly . Ruby . characterSetVariable_ = function ( name , val , operator ) {
184181 if ( operator == null ) {
185182 operator = '=' ;
186183 }
187184 if ( this . c_ ( ) ) {
188- return "" + ( this . rn_ ( {
185+ return ` ${ this . rn_ ( {
189186 dropSelf : false
190- } ) ) + name + " " + operator + " " + val + "\n" ;
191- } else {
192- return '' ;
187+ } ) } ${ name } ${ operator } ${ val } \n`;
193188 }
189+ return '' ;
194190 } ;
195191
196- Blockly . Ruby . characterEvent_ = function ( block , bodyName , name , arg ) {
197- var body , c ;
192+ Blockly . Ruby . characterEvent_ = function ( block , bodyName , name , arg ) {
193+ let body ; let c ;
198194 if ( arg == null ) {
199195 arg = null ;
200196 }
@@ -206,32 +202,30 @@ export default function (Blockly) {
206202 this . rs_ ( ) . pop ( ) ;
207203 }
208204 if ( arg ) {
209- arg = ", " + arg ;
205+ arg = `, ${ arg } ` ;
210206 } else {
211207 arg = '' ;
212208 }
213- return "\n\n" + ( this . rn_ ( ) ) + "on(:" + name + arg + ") do\n" + body + "end\n" ;
214- } else {
215- return '' ;
209+ return `\n\n${ this . rn_ ( ) } on(:${ name } ${ arg } ) do\n${ body } end\n` ;
216210 }
211+ return '' ;
217212 } ;
218213
219- Blockly . Ruby . finish = function ( code ) {
220- var allDefs , definitions , name , prepares , requires , _fn ;
214+ Blockly . Ruby . finish = function ( code ) {
215+ let allDefs ; let definitions ; let name ; let prepares ; let requires ; let _fn ;
221216 requires = [ ] ;
222217 prepares = [ ] ;
223218 definitions = [ ] ;
224- _fn = function ( name ) {
225- var def ;
219+ _fn = function ( name ) {
220+ let def ;
226221 def = Blockly . Ruby . definitions_ [ name ] ;
227222 if ( _ . isString ( def ) ) {
228223 if ( name . match ( / ^ r e q u i r e _ _ / ) ) {
229224 return requires . push ( def ) ;
230225 } else if ( name . match ( / ^ p r e p a r e _ _ / ) ) {
231226 return prepares . push ( def ) ;
232- } else {
233- return definitions . push ( def ) ;
234227 }
228+ return definitions . push ( def ) ;
235229 }
236230 } ;
237231 for ( name in Blockly . Ruby . definitions_ ) {
@@ -240,55 +234,56 @@ export default function (Blockly) {
240234 if ( prepares . length === 0 && definitions . length === 0 && code . length === 0 ) {
241235 return '' ;
242236 }
243- allDefs = requires . join ( '\n' ) + ' \n\n' ;
237+ allDefs = ` ${ requires . join ( '\n' ) } \n\n` ;
244238 if ( prepares . length > 0 ) {
245- allDefs += prepares . join ( '\n' ) + ' \n\n' ;
239+ allDefs += ` ${ prepares . join ( '\n' ) } \n\n` ;
246240 }
247241 if ( definitions . length > 0 ) {
248- allDefs += definitions . join ( '\n' ) . replace ( / \n \n + / g, '\n\n' ) . replace ( / \n * $ / , '\n' ) ;
242+ allDefs += definitions . join ( '\n' ) . replace ( / \n \n + / g, '\n\n' )
243+ . replace ( / \n * $ / , '\n' ) ;
249244 }
250245 return allDefs + code ;
251246 } ;
252247
253- Blockly . Ruby . scrubNakedValue = function ( line ) {
254- return line + '\n' ;
248+ Blockly . Ruby . scrubNakedValue = function ( line ) {
249+ return ` ${ line } \n` ;
255250 } ;
256251
257252 Blockly . Ruby . escapeChars_ = {
258253 '"' : '\\"'
259254 } ;
260255
261- Blockly . Ruby . quote_ = function ( string ) {
262- var i , s , sb , _fn , _i , _ref ;
256+ Blockly . Ruby . quote_ = function ( string ) {
257+ let i ; let s ; let sb ; let _fn ; let _i ; let _ref ;
263258 s = String ( string ) ;
264259 sb = [ '"' ] ;
265- _fn = function ( i ) {
266- var ch ;
260+ _fn = function ( i ) {
261+ let ch ;
267262 ch = s . charAt ( i ) ;
268263 return sb [ i + 1 ] = Blockly . Ruby . escapeChars_ [ ch ] || ch ;
269264 } ;
270- for ( i = _i = 0 , _ref = s . length ; 0 <= _ref ? _i < _ref : _i > _ref ; i = 0 <= _ref ? ++ _i : -- _i ) {
265+ for ( i = _i = 0 , _ref = s . length ; _ref >= 0 ? _i < _ref : _i > _ref ; i = _ref >= 0 ? ++ _i : -- _i ) {
271266 _fn ( i ) ;
272267 }
273268 sb . push ( '"' ) ;
274269 return sb . join ( '' ) ;
275270 } ;
276271
277- Blockly . Ruby . scrub_ = function ( block , code ) {
278- var comment , commentCode , input , nextBlock , nextCode , _fn , _i , _len , _ref ;
272+ Blockly . Ruby . scrub_ = function ( block , code ) {
273+ let comment ; let commentCode ; let input ; let nextBlock ; let nextCode ; let _fn ; let _i ; let _len ; let _ref ;
279274 if ( code === null ) {
280275 return '' ;
281276 }
282277 commentCode = '' ;
283278 if ( ! block . outputConnection || ! block . outputConnection . targetConnection ) {
284279 comment = block . getCommentText ( ) ;
285280 if ( comment ) {
286- commentCode += this . prefixLines ( comment , '# ' ) + '\n' ;
281+ commentCode += ` ${ this . prefixLines ( comment , '# ' ) } \n` ;
287282 }
288283 _ref = block . inputList ;
289- _fn = ( function ( _this ) {
290- return function ( input ) {
291- var childBlock ;
284+ _fn = ( function ( _this ) {
285+ return function ( input ) {
286+ let childBlock ;
292287 if ( input . type === Blockly . INPUT_VALUE ) {
293288 childBlock = input . connection . targetBlock ( ) ;
294289 if ( childBlock ) {
@@ -299,7 +294,7 @@ export default function (Blockly) {
299294 }
300295 }
301296 } ;
302- } ) ( this ) ;
297+ } ( this ) ) ;
303298 for ( _i = 0 , _len = _ref . length ; _i < _len ; _i ++ ) {
304299 input = _ref [ _i ] ;
305300 _fn ( input ) ;
@@ -318,24 +313,22 @@ export default function (Blockly) {
318313 return commentCode + code + nextCode + eventEndCode ;
319314 } ;
320315
321- Blockly . Ruby . spriteName = function ( ) {
316+ Blockly . Ruby . spriteName = function ( ) {
322317 return this . editingTarget . sprite . name ;
323318 } ;
324319
325320 Blockly . Ruby . broadcastMessageName = function ( name ) {
326321 const bm = this . editingTarget . lookupBroadcastMsg ( name ) ;
327- let message = null ;
322+ const message = null ;
328323 if ( bm ) {
329324 return Blockly . Ruby . quote_ ( bm . name ) ;
330325 }
331- else {
332- return null ;
333- }
326+ return null ;
334327 } ;
335328
336329 Blockly . Ruby . workspaceToCode_ = Blockly . Ruby . workspaceToCode ;
337330
338- Blockly . Ruby . workspaceToCode = function ( block , target ) {
331+ Blockly . Ruby . workspaceToCode = function ( block , target ) {
339332 if ( target ) {
340333 this . editingTarget = target ;
341334 }
@@ -344,9 +337,9 @@ export default function (Blockly) {
344337
345338 Blockly . Ruby . blockToCode_ = Blockly . Ruby . blockToCode ;
346339
347- Blockly . Ruby . blockToCode = function ( block ) {
340+ Blockly . Ruby . blockToCode = function ( block ) {
348341 if ( block && ! block . disabled && block . type . match ( / ^ h a r d w a r e _ / ) ) {
349- this . definitions_ [ ' prepare__init_hardware' ] = 'init_hardware' ;
342+ this . definitions_ . prepare__init_hardware = 'init_hardware' ;
350343 }
351344 return this . blockToCode_ ( block ) ;
352345 } ;
@@ -356,20 +349,18 @@ export default function (Blockly) {
356349 '_mouse_' ,
357350 '_edge_' ,
358351 '_random_' ,
359- '_stage_' ,
352+ '_stage_'
360353 ] ;
361354
362- Blockly . Ruby . isSpecialSymbol = function ( name ) {
355+ Blockly . Ruby . isSpecialSymbol = function ( name ) {
363356 return this . SpecialSymbols . includes ( name ) ;
364357 } ;
365358
366- Blockly . Ruby . specialSymbolToCode = function ( name ) {
359+ Blockly . Ruby . specialSymbolToCode = function ( name ) {
367360 if ( this . isSpecialSymbol ( name ) ) {
368361 return `:${ name } ` ;
369362 }
370- else {
371- return name ;
372- }
363+ return name ;
373364 } ;
374365
375366 Blockly = GeneratedBlocks ( Blockly ) ;
0 commit comments