From 74fd92dc48f9575abc701fbd84decad160c5cc6d Mon Sep 17 00:00:00 2001 From: Corban Brook Date: Mon, 11 Nov 2013 22:07:45 -0500 Subject: [PATCH] feature: Optional configuration target --- lib/configwriter.js | 8 +++-- lib/file.js | 30 ++++++++++++------- .../optional_configuration_target.html | 13 ++++++++ test/test-file.js | 7 +++++ 4 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 test/fixtures/optional_configuration_target.html diff --git a/lib/configwriter.js b/lib/configwriter.js index b3984a8..2d7c227 100644 --- a/lib/configwriter.js +++ b/lib/configwriter.js @@ -153,16 +153,18 @@ ConfigWriter.prototype.process = function(file, config) { context.inDir = block.searchPath[0]; } self.forEachStep(block.type, function(writer, last) { + // Use the default 'generated' target unless a configuration target was specified + var target = block.target || 'generated'; // If this is the last writer of the pipe, we need to output // in the destination directory context.outDir = last ? self.dest : path.join(self.staging, writer.name); context.last = last; config[writer.name] = config[writer.name] || {}; - config[writer.name].generated = config[writer.name].generated || {}; + config[writer.name][target] = config[writer.name][target] || {}; context.options = config[writer.name]; - // config[writer.name].generated = _.extend(config[writer.name].generated, writer.createConfig(context, block)); - config[writer.name].generated = deepMerge(config[writer.name].generated, writer.createConfig(context, block)); + // config[writer.name][target] = _.extend(config[writer.name][target], writer.createConfig(context, block)); + config[writer.name][target] = deepMerge(config[writer.name][target], writer.createConfig(context, block)); context.inDir = context.outDir; context.inFiles = context.outFiles; context.outFiles = []; diff --git a/lib/file.js b/lib/file.js index a677ccd..733d45c 100644 --- a/lib/file.js +++ b/lib/file.js @@ -35,15 +35,20 @@ var fs = require('fs'); // var getBlocks = function (content) { // start build pattern: will match - // * - // * + // * + // * + // * + // * + // The following matching param are set when there's match // * 0 : the whole matched expression - // * 1 : the target (ie. type) - // * 2 : the alternate search path - // * 3 : the output + // * 1 : the type (ie. js, css) + // * 2 : an optional configuration target + // * 3 : the alternate search path + // * 4 : the output // - var regbuild = //; + var regbuild = //; + // end build pattern -- var regend = //; @@ -62,13 +67,13 @@ var getBlocks = function (content) { if (build) { block = true; // Handle absolute path (i.e. with respect to the server root) - // if (build[3][0] === '/') { + // if (build[4][0] === '/') { // startFromRoot = true; - // build[3] = build[3].substr(1); + // build[4] = build[4].substr(1); // } last = { type: build[1], - dest: build[3], + dest: build[4], startFromRoot: startFromRoot, indent: indent, searchPath: [], @@ -77,8 +82,13 @@ var getBlocks = function (content) { }; if (build[2]) { + // Optional configuration target + last.target = build[2]; + } + + if (build[3]) { // Alternate search path - last.searchPath.push(build[2]); + last.searchPath.push(build[3]); } } // Check IE conditionals diff --git a/test/fixtures/optional_configuration_target.html b/test/fixtures/optional_configuration_target.html new file mode 100644 index 0000000..56cfe8f --- /dev/null +++ b/test/fixtures/optional_configuration_target.html @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/test/test-file.js b/test/test-file.js index ad75331..6af1132 100644 --- a/test/test-file.js +++ b/test/test-file.js @@ -148,5 +148,12 @@ describe('File', function() { assert.equal('(min-width:980px)', file.blocks[0].media); }); + it('should detect an optional configuration target', function() { + var filename = __dirname + '/fixtures/optional_configuration_target.html'; + var file = new File(filename); + assert.equal(1, file.blocks.length); + assert.ok(file.blocks[0].target); + assert.equal('thirdparty', file.blocks[0].target); + }); });