components/blockly-src/demos/blockfactory/factory.js
function formatJavaScript_(blockType, rootBlock) {
  var code = [];
  code.push("Blockly.Blocks['" + blockType + "'] = {");
  code.push("  init: function() {");
  // Generate inputs.
  var TYPES = {'input_value': 'appendValueInput',
               'input_statement': 'appendStatementInput',
               'input_dummy': 'appendDummyInput'};
  var contentsBlock = rootBlock.getInputTargetBlock('INPUTS');
  while (contentsBlock) {
    if (!contentsBlock.disabled && !contentsBlock.getInheritedDisabled()) {
      var name = '';
      // Dummy inputs don't have names.  Other inputs do.
      if (contentsBlock.type != 'input_dummy') {
        name = escapeString(contentsBlock.getFieldValue('INPUTNAME'));
      }
      code.push('    this.' + TYPES[contentsBlock.type] + '(' + name + ')');
      var check = getOptTypesFrom(contentsBlock, 'TYPE');
      if (check) {
        code.push('        .setCheck(' + check + ')');
      }
      var align = contentsBlock.getFieldValue('ALIGN');
      if (align != 'LEFT') {
        code.push('        .setAlign(Blockly.ALIGN_' + align + ')');
      }
      var fields = getFieldsJs_(contentsBlock.getInputTargetBlock('FIELDS'));
      for (var i = 0; i < fields.length; i++) {
        code.push('        .appendField(' + fields[i] + ')');
      }
      // Add semicolon to last line to finish the statement.
      code[code.length - 1] += ';';
    }
    contentsBlock = contentsBlock.nextConnection &&
        contentsBlock.nextConnection.targetBlock();
  }
  // Generate inline/external switch.
  if (rootBlock.getFieldValue('INLINE') == 'EXT') {
    code.push('    this.setInputsInline(false);');
  } else if (rootBlock.getFieldValue('INLINE') == 'INT') {
    code.push('    this.setInputsInline(true);');
  }
  // Generate output, or next/previous connections.
  switch (rootBlock.getFieldValue('CONNECTIONS')) {
    case 'LEFT':
      code.push(connectionLineJs_('setOutput', 'OUTPUTTYPE'));
      break;
    case 'BOTH':
      code.push(connectionLineJs_('setPreviousStatement', 'TOPTYPE'));
      code.push(connectionLineJs_('setNextStatement', 'BOTTOMTYPE'));
      break;
    case 'TOP':
      code.push(connectionLineJs_('setPreviousStatement', 'TOPTYPE'));
      break;
    case 'BOTTOM':
      code.push(connectionLineJs_('setNextStatement', 'BOTTOMTYPE'));
      break;
  }
  // Generate colour.
  var colourBlock = rootBlock.getInputTargetBlock('COLOUR');
  if (colourBlock && !colourBlock.disabled) {
    var hue = parseInt(colourBlock.getFieldValue('HUE'), 10);
    if (!isNaN(hue)) {
      code.push('    this.setColour(' + hue + ');');
    }
  }
  code.push("    this.setTooltip('');");
  code.push("    this.setHelpUrl('http://www.example.com/');");
  code.push('  }');
  code.push('};');
  return code.join('\n');
}
function formatJavaScript_(blockType, rootBlock) {
  var code = [];
  code.push("Blockly.Blocks['" + blockType + "'] = {");
  code.push("  init: function() {");
  // Generate inputs.
  var TYPES = {'input_value': 'appendValueInput',
               'input_statement': 'appendStatementInput',
               'input_dummy': 'appendDummyInput'};
  var contentsBlock = rootBlock.getInputTargetBlock('INPUTS');
  while (contentsBlock) {
    if (!contentsBlock.disabled && !contentsBlock.getInheritedDisabled()) {
      var name = '';
      // Dummy inputs don't have names.  Other inputs do.
      if (contentsBlock.type != 'input_dummy') {
        name = escapeString(contentsBlock.getFieldValue('INPUTNAME'));
      }
      code.push('    this.' + TYPES[contentsBlock.type] + '(' + name + ')');
      var check = getOptTypesFrom(contentsBlock, 'TYPE');
      if (check) {
        code.push('        .setCheck(' + check + ')');
      }
      var align = contentsBlock.getFieldValue('ALIGN');
      if (align != 'LEFT') {
        code.push('        .setAlign(Blockly.ALIGN_' + align + ')');
      }
      var fields = getFieldsJs_(contentsBlock.getInputTargetBlock('FIELDS'));
      for (var i = 0; i < fields.length; i++) {
        code.push('        .appendField(' + fields[i] + ')');
      }
      // Add semicolon to last line to finish the statement.
      code[code.length - 1] += ';';
    }
    contentsBlock = contentsBlock.nextConnection &&
        contentsBlock.nextConnection.targetBlock();
  }
  // Generate inline/external switch.
  if (rootBlock.getFieldValue('INLINE') == 'EXT') {
    code.push('    this.setInputsInline(false);');
  } else if (rootBlock.getFieldValue('INLINE') == 'INT') {
    code.push('    this.setInputsInline(true);');
  }
  // Generate output, or next/previous connections.
  switch (rootBlock.getFieldValue('CONNECTIONS')) {
    case 'LEFT':
      code.push(connectionLineJs_('setOutput', 'OUTPUTTYPE'));
      break;
    case 'BOTH':
      code.push(connectionLineJs_('setPreviousStatement', 'TOPTYPE'));
      code.push(connectionLineJs_('setNextStatement', 'BOTTOMTYPE'));
      break;
    case 'TOP':
      code.push(connectionLineJs_('setPreviousStatement', 'TOPTYPE'));
      break;
    case 'BOTTOM':
      code.push(connectionLineJs_('setNextStatement', 'BOTTOMTYPE'));
      break;
  }
  // Generate colour.
  var colourBlock = rootBlock.getInputTargetBlock('COLOUR');
  if (colourBlock && !colourBlock.disabled) {
    var hue = parseInt(colourBlock.getFieldValue('HUE'), 10);
    if (!isNaN(hue)) {
      code.push('    this.setColour(' + hue + ');');
    }
  }
  code.push("    this.setTooltip('');");
  code.push("    this.setHelpUrl('http://www.example.com/');");
  code.push('  }');
  code.push('};');
  return code.join('\n');
}
function formatJavaScript_ ( blockType , rootBlock ) { var code = [ ] ; code . push ( "Blockly.Blocks['" + blockType + "'] = {" ) ; code . push ( "  init: function() {" ) ; // Generate inputs. var TYPES = { 'input_value' : 'appendValueInput' , 'input_statement' : 'appendStatementInput' , 'input_dummy' : 'appendDummyInput' } ; var contentsBlock = rootBlock . getInputTargetBlock ( 'INPUTS' ) ; while ( contentsBlock ) { if ( ! contentsBlock . disabled && ! contentsBlock . getInheritedDisabled ( ) ) { var name = '' ; // Dummy inputs don't have names.  Other inputs do. if ( contentsBlock . type != 'input_dummy' ) { name = escapeString ( contentsBlock . getFieldValue ( 'INPUTNAME' ) ) ; } code . push ( '    this.' + TYPES [ contentsBlock . type ] + '(' + name + ')' ) ; var check = getOptTypesFrom ( contentsBlock , 'TYPE' ) ; if ( check ) { code . push ( '        .setCheck(' + check + ')' ) ; } var align = contentsBlock . getFieldValue ( 'ALIGN' ) ; if ( align != 'LEFT' ) { code . push ( '        .setAlign(Blockly.ALIGN_' + align + ')' ) ; } var fields = getFieldsJs_ ( contentsBlock . getInputTargetBlock ( 'FIELDS' ) ) ; for ( var i = 0 ; i < fields . length ; i ++ ) { code . push ( '        .appendField(' + fields [ i ] + ')' ) ; } // Add semicolon to last line to finish the statement. code [ code . length - 1 ] += ';' ; } contentsBlock = contentsBlock . nextConnection && contentsBlock . nextConnection . targetBlock ( ) ; } // Generate inline/external switch. if ( rootBlock . getFieldValue ( 'INLINE' ) == 'EXT' ) { code . push ( '    this.setInputsInline(false);' ) ; } else if ( rootBlock . getFieldValue ( 'INLINE' ) == 'INT' ) { code . push ( '    this.setInputsInline(true);' ) ; } // Generate output, or next/previous connections. switch ( rootBlock . getFieldValue ( 'CONNECTIONS' ) ) { case 'LEFT' : code . push ( connectionLineJs_ ( 'setOutput' , 'OUTPUTTYPE' ) ) ; break ; case 'BOTH' : code . push ( connectionLineJs_ ( 'setPreviousStatement' , 'TOPTYPE' ) ) ; code . push ( connectionLineJs_ ( 'setNextStatement' , 'BOTTOMTYPE' ) ) ; break ; case 'TOP' : code . push ( connectionLineJs_ ( 'setPreviousStatement' , 'TOPTYPE' ) ) ; break ; case 'BOTTOM' : code . push ( connectionLineJs_ ( 'setNextStatement' , 'BOTTOMTYPE' ) ) ; break ; } // Generate colour. var colourBlock = rootBlock . getInputTargetBlock ( 'COLOUR' ) ; if ( colourBlock && ! colourBlock . disabled ) { var hue = parseInt ( colourBlock . getFieldValue ( 'HUE' ) , 10 ) ; if ( ! isNaN ( hue ) ) { code . push ( '    this.setColour(' + hue + ');' ) ; } } code . push ( "    this.setTooltip('');" ) ; code . push ( "    this.setHelpUrl('http://www.example.com/');" ) ; code . push ( '  }' ) ; code . push ( '};' ) ; return code . join ( '\n' ) ; }
Update the language code as JavaScript.
@param {string} blockType Name of block.
@param {!Blockly.Block} rootBlock Factory_base block.
@return {string} Generanted language code.
@private
Update the language code as JavaScript .