# 「Ruby」ジャンル <% category = 'ruby' require 'smalruby_editor' require 'smalruby_editor/blockly_message_helper' color = SmalrubyEditor::COLORS[category.to_sym] %> # 文 <% n = "#{category}_statement" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput() .appendField(<%= bm('.statement') %>) .appendField(new Blockly.FieldTextInput(''), 'STATEMENT') @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> statement = @getFieldValue('STATEMENT') "#{statement}\n" # 式 <% n = "#{category}_expression" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput() .appendField(<%= bm('.expression') %>) .appendField(new Blockly.FieldTextInput(''), 'EXP') @setOutput(true, null) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> exp = @getFieldValue('EXP') ["(#{exp})", Blockly.Ruby.ORDER_ATOMIC] # コメント <% n = "#{category}_comment" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @appendDummyInput() .appendField(<%= bm('.comment') %>) .appendField(new Blockly.FieldTextInput(''), 'COMMENT') @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> comment = @getFieldValue('COMMENT') "# #{comment}\n" # p <% n = "#{category}_p" %> Blockly.Blocks['<%= n %>'] = init: ()-> @setHelpUrl('') @setColour(<%= color %>) @interpolateMsg('p %1', ['ARG', null, Blockly.ALIGN_RIGHT], Blockly.ALIGN_RIGHT) @setInputsInline(true) @setPreviousStatement(true) @setNextStatement(true) @setTooltip('') Blockly.Ruby['<%= n %>'] = (block) -> arg = Blockly.Ruby.valueToCode(@, 'ARG', Blockly.Ruby.ORDER_NONE) || '""' "p(#{arg})\n"