From 0063159c590864596be479f3a13149919ce35c5e Mon Sep 17 00:00:00 2001 From: Brian Broll Date: Sat, 28 Jan 2017 12:38:23 -0600 Subject: [PATCH 1/2] WIP #963 Added support for extension objects (not just fns) --- src/plugins/Export/Export.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/plugins/Export/Export.js b/src/plugins/Export/Export.js index 9ec20a6a1..d585a739b 100644 --- a/src/plugins/Export/Export.js +++ b/src/plugins/Export/Export.js @@ -123,6 +123,22 @@ define([ return config; }; + Export.prototype.getExporterFor = function (name) { + var Exporter = function() {}, + format = FORMATS[name], + exporter; + + Exporter.prototype = this; + exporter = new Exporter(); + + if (typeof format === 'function') { + exporter.main = format; + } else { + _.extend(exporter, format); + } + return exporter; + }; + Export.prototype.generateOutputFiles = function (children) { var name = this.core.getAttribute(this.activeNode, 'name'); @@ -131,10 +147,12 @@ define([ // Get the selected format var config = this.getCurrentConfig(), format = config.format || 'Basic CLI', - generate = FORMATS[format], + exporter, staticInputs, files; + exporter = this.getExporterFor(format); + staticInputs = config.staticInputs.map(id => { var opId = id.split('/').splice(0, this.activeNodeDepth).join('/'), port = this._portCache[id]; @@ -147,7 +165,7 @@ define([ }; }); - files = generate.call(this, sections, staticInputs); + files = exporter.main(sections, staticInputs); // If it returns a string, just put a single file if (typeof files === 'string') { return this.blobClient.putFile(`${name}.lua`, files); From da2b4f67af23ec8d8c8c8fea3a051d5677dc3c50 Mon Sep 17 00:00:00 2001 From: Brian Broll Date: Sat, 28 Jan 2017 12:38:56 -0600 Subject: [PATCH 2/2] WIP #963 Updated the cli exporter to extension object format --- src/plugins/Export/formats/cli/cli.js | 29 ++++++++++++++------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/plugins/Export/formats/cli/cli.js b/src/plugins/Export/formats/cli/cli.js index 5c1fd6e99..f166fde43 100644 --- a/src/plugins/Export/formats/cli/cli.js +++ b/src/plugins/Export/formats/cli/cli.js @@ -4,9 +4,18 @@ define([ ], function( ) { - var TOBOOLEAN; + var TOBOOLEAN = +`local function toboolean(str) + if str == 'true' then + return true + elseif str == 'false' then + return false + end +end`; + + var CliExporter = {}; - var deserializersFromString = function(sections) { + CliExporter.deserializersFromString = function(sections) { var hasBool = false; // Add serializers given cli string input @@ -33,13 +42,14 @@ define([ return sections; }; - var createExecFile = function (sections, staticInputs) { + CliExporter.main = function (sections, staticInputs) { var code = []; // Update deserializers for cli input - deserializersFromString.call(this, sections); + this.deserializersFromString(sections); // Define all the operations, pipelines, etc + // 'getAllDefinitions' is provided as part of the public api code.push(this.getAllDefinitions(sections)); // Command line specific stuff @@ -90,14 +100,5 @@ define([ return staticInputs.length ? files : files['init.lua']; }; - TOBOOLEAN = -`local function toboolean(str) - if str == 'true' then - return true - elseif str == 'false' then - return false - end -end`; - - return createExecFile; + return CliExporter; });