Skip to content

Commit

Permalink
feat: configurable $templateCache key
Browse files Browse the repository at this point in the history
````javascript
karma.configure({
  ngHtml2JsPreprocessor: {
    cacheIdFromPath: function(filepath) {
      return '/prefix/' + filepath;
    }
  }
});
````

Closes #7
  • Loading branch information
vojtajina committed May 6, 2013
1 parent 6fbe6f9 commit 5b59ac6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/html2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@ var escapeContent = function(content) {
return content.replace(/'/g, '\\\'').replace(/\r?\n/g, '\\n\' +\n \'');
};

var createHtml2JsPreprocessor = function(logger, basePath) {
var createHtml2JsPreprocessor = function(logger, basePath, config) {
config = typeof config === 'object' ? config : {};

var log = logger.create('preprocessor.html2js');
var stripPrefix = new RegExp('^' + (config.stripPrefix || ''));
var prependPrefix = config.prependPrefix || '';
var cacheIdFromPath = config && config.cacheIdFromPath || function(filepath) {
return prependPrefix + filepath.replace(stripPrefix, '');
};

return function(content, file, done) {
log.debug('Processing "%s".', file.originalPath);

var htmlPath = file.originalPath.replace(basePath + '/', '');
var htmlPath = cacheIdFromPath(file.originalPath.replace(basePath + '/', ''));

file.path = file.path + '.js';
done(util.format(TEMPLATE, htmlPath, htmlPath, escapeContent(content)));
};
};

createHtml2JsPreprocessor.$inject = ['logger', 'config.basePath'];
createHtml2JsPreprocessor.$inject = ['logger', 'config.basePath', 'config.ngHtml2JsPreprocessor'];

module.exports = createHtml2JsPreprocessor;

0 comments on commit 5b59ac6

Please sign in to comment.