diff --git a/core/lib/pattern_engines.js b/core/lib/pattern_engines.js index 8ca2aea2a..7582b4ea7 100644 --- a/core/lib/pattern_engines.js +++ b/core/lib/pattern_engines.js @@ -123,12 +123,19 @@ const PatternEngines = Object.create({ const of = require('./object_factory'); if (pattern instanceof of.Pattern && typeof pattern.fileExtension === 'string' && pattern.fileExtension) { //loop through known engines and find the one that supports the pattern's fileExtension - //TODO: support multiple extensions someday, such as .handlebars and .hbs const engineNames = Object.keys(this); for (let i = 0; i < engineNames.length; i++) { const engine = this[engineNames[i]]; - if (engine.engineFileExtension === pattern.fileExtension) { - return engine.engineName; + + if (Array.isArray(engine.engineFileExtension)) { + if (engine.engineFileExtension.includes(pattern.fileExtension)) { + return engine.engineName; + } + } else { + //this likely means the users engines are out of date. todo: tell them to upgrade + if (engine.engineFileExtension === pattern.fileExtension) { + return engine.engineName; + } } } } @@ -147,11 +154,13 @@ const PatternEngines = Object.create({ } }, + // combine all found engines into a single array of supported extensions getSupportedFileExtensions: function () { const engineNames = Object.keys(PatternEngines); - return engineNames.map(function (engineName) { + const allEnginesExtensions = engineNames.map((engineName) => { return PatternEngines[engineName].engineFileExtension; }); + return [].concat.apply([], allEnginesExtensions); }, isFileExtensionSupported: function (fileExtension) { diff --git a/test/pattern_engines_tests.js b/test/pattern_engines_tests.js index 893dd031f..0d20e73ad 100644 --- a/test/pattern_engines_tests.js +++ b/test/pattern_engines_tests.js @@ -125,7 +125,7 @@ function testProps(object, propTests, test) { }); test.ok(object.hasOwnProperty(propName), '"' + propName + '" prop should be present'); - test.ok(isOneOfTheseTypes, '"' + propName + '" prop should be one of types ' + possibleTypes); + test.ok(isOneOfTheseTypes, '"' + propName + '" prop should be one of types ' + possibleTypes + ' but was instead ' + typeof propName); } // go over each property test and run it @@ -154,7 +154,7 @@ engineNames.forEach(function (engineName) { var propertyTests = { 'engine': ['object', 'function'], 'engineName': 'string', - 'engineFileExtension': 'string', + 'engineFileExtension': ['string', 'object'], 'renderPattern': 'function', 'findPartials': 'function' }; @@ -164,3 +164,24 @@ engineNames.forEach(function (engineName) { test.end(); }); }); + +tap.test('patternEngines getSupportedFileExtensions flattens known engine extensions into a single array', function (test) { + + //arrange + patternEngines.fooEngine = { + engineFileExtension : ['.foo1', '.foo2'] + }; + patternEngines.barEngine = { + engineFileExtension : '.bar' + }; + + const exts = patternEngines.getSupportedFileExtensions(); + test.ok(exts.includes('.foo1')); + test.ok(exts.includes('.foo2')); + test.ok(exts.includes('.bar')); + + delete patternEngines.fooEngine; + delete patternEngines.barEngine; + + test.end(); +});