BlockFactory: Adding JSON/JavaScript import support (#1235)

Updates the BlockFactory main workspace based on the preview block generated from manual construction.

This is a continuation of PR #1216 by @JC-Orozco, rebased on latest develop branch. Bring it latest code up to Google styling and standards.
This commit is contained in:
Andrew n marshall
2017-08-17 12:40:58 -07:00
committed by GitHub
parent 29582ba0d7
commit 1956baa963
6 changed files with 878 additions and 35 deletions

View File

@@ -24,15 +24,18 @@
* Exporter applications within Blockly Factory. Holds functions to generate
* block definitions and generator stubs and to create and download files.
*
* @author fraser@google.com (Neil Fraser), quachtina96 (Tina Quach)
* @author fraser@google.com (Neil Fraser), quachtina96 (Tina Quach), JC-Orozco
* (Juan Carlos Orozco)
*/
'use strict';
'use strict';
/**
* Namespace for FactoryUtils.
*/
goog.provide('FactoryUtils');
goog.require('BlockDefinitionExtractor');
/**
* Get block definition code for the current block.
@@ -73,10 +76,23 @@ FactoryUtils.cleanBlockType = function(blockType) {
* Get the generator code for a given block.
* @param {!Blockly.Block} block Rendered block in preview workspace.
* @param {string} generatorLanguage 'JavaScript', 'Python', 'PHP', 'Lua',
* 'Dart'.
* or 'Dart'.
* @return {string} Generator code for multiple blocks.
*/
FactoryUtils.getGeneratorStub = function(block, generatorLanguage) {
// Build factory blocks from block
if (BlockFactory.updateBlocksFlag) { // TODO: Move this to updatePreview()
BlockFactory.mainWorkspace.clear();
var xml = BlockDefinitionExtractor.buildBlockFactoryWorkspace(block);
Blockly.Xml.domToWorkspace(xml, BlockFactory.mainWorkspace);
// Calculate timer to avoid infinite update loops
// TODO(#1267): Remove the global variables and any infinite loops.
BlockFactory.updateBlocksFlag = false;
setTimeout(
function() {BlockFactory.updateBlocksFlagDelayed = false;}, 3000);
}
BlockFactory.lastUpdatedBlock = block; // Variable to share the block value.
function makeVar(root, name) {
name = name.toLowerCase().replace(/\W/g, '_');
return ' var ' + root + '_' + name;