Skip to content

Commit

Permalink
feat: Add stripSufix config option
Browse files Browse the repository at this point in the history
Works in the same way as `stripPrefix` but with sufix.

Closes #37
Closes #38
  • Loading branch information
jandudulski authored and pkozlowski-opensource committed Oct 15, 2014
1 parent 3e77c50 commit e0e6126
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ module.exports = function(config) {
files: [
'*.js',
'*.html',
'*.html.ext',
// if you wanna load template files in nested directories, you must use this
'**/*.html'
],

ngHtml2JsPreprocessor: {
// strip this from the file path
stripPrefix: 'public/',
stripSufix: '.ext',
// prepend this to the
prependPrefix: 'served/',

Expand Down
3 changes: 2 additions & 1 deletion lib/html2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions test/html2js.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<html></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
Expand Down

0 comments on commit e0e6126

Please sign in to comment.