Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stripSufix config option #38

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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