From dc2df294a4d3592b65e78941579ddfcc0f3ff781 Mon Sep 17 00:00:00 2001 From: Brian Broll Date: Sat, 28 Jan 2017 12:49:05 -0600 Subject: [PATCH] Added support for export pipeline extension objects. Fixes #963 (#964) * WIP #963 Added support for extension objects (not just fns) * WIP #963 Updated the cli exporter to extension object format --- src/plugins/Export/Export.js | 22 ++++++++++++++++++-- src/plugins/Export/formats/cli/cli.js | 29 ++++++++++++++------------- 2 files changed, 35 insertions(+), 16 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); 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; });