diff --git a/README.md b/README.md index 66e9586..a7bcbc0 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ module.exports = function(config) { files: [ '*.js', '*.html', + '*.html.ext', // if you wanna load template files in nested directories, you must use this '**/*.html' ], @@ -40,6 +41,7 @@ module.exports = function(config) { ngHtml2JsPreprocessor: { // strip this from the file path stripPrefix: 'public/', + stripSufix: '.ext', // prepend this to the prependPrefix: 'served/', diff --git a/lib/html2js.js b/lib/html2js.js index 18635ca..13763b8 100644 --- a/lib/html2js.js +++ b/lib/html2js.js @@ -27,8 +27,9 @@ var createHtml2JsPreprocessor = function(logger, basePath, config) { var moduleName = config.moduleName; var stripPrefix = new RegExp('^' + (config.stripPrefix || '')); var prependPrefix = config.prependPrefix || ''; + var stripSufix = new RegExp((config.stripSufix || '') + '$'); var cacheIdFromPath = config && config.cacheIdFromPath || function(filepath) { - return prependPrefix + filepath.replace(stripPrefix, ''); + return prependPrefix + filepath.replace(stripPrefix, '').replace(stripSufix, ''); }; return function(content, file, done) { diff --git a/test/html2js.spec.coffee b/test/html2js.spec.coffee index 0c0c91f..546836e 100644 --- a/test/html2js.spec.coffee +++ b/test/html2js.spec.coffee @@ -109,6 +109,23 @@ describe 'preprocessors html2js', -> done() + describe 'stripSufix', -> + beforeEach -> + process = createPreprocessor stripSufix: '.ext' + + + it 'strips the given sufix from the file path', (done) -> + file = new File 'file.html.ext' + HTML = '' + + process HTML, file, (processedContent) -> + expect(processedContent) + .to.defineModule('file.html').and + .to.defineTemplateId('file.html').and + .to.haveContent HTML + done() + + describe 'cacheIdFromPath', -> beforeEach -> process = createPreprocessor