karma-ng-html2js-preprocessor
karma-ng-html2js-preprocessor copied to clipboard
prependPrefix and cacheIdFromPath doesn't allow absolute paths
Hi,
Unless I'm missing something, I can't seem to get absolute paths for my templates. Both prependPrefix and cacheIdFromPath strips the initial /.
I'm using Angular in some Drupal modules and themes, and that means that they don't exist in the root but in a sub-subdirectories, and the page runs from the root with clean URLs, making relative template calls a problem.
I specify it as follows:
ngHtml2JsPreprocessor: {
prependPrefix: '/sites/all/modules/_custom/',
cacheIdFromPath: function(filepath) {
return '/sites/all/modules/_custom/' + filepath;
}
}
..but it strips the initial / as per the following:
angular.module('sites/all/modules/_custom/list.html', []).run(function($templateCache) {
$templateCache.put('sites/all/modules/_custom/list.html',
'angular.module(\'sites/all/modules/_custom/list.html\', []).run(function($templateCache) {\n' +
' $templateCache.put(\'sites/all/modules/_custom/list.html\',\n' +
' \'<span>test</span +\n' +
' \'\');\n' +
'});\n' +
'');
});
..causing the following error:
Error: No module: /sites/all/modules/_custom/list.html
It works if I manually add a html.js file with the absolute path.
karma: v0.10.2 karma-ng-html2js-preprocessor: v0.1.0 node: v0.10.20
Same issue with html2js task ! :) Would be great if that could work.
Subscribing. Having the exact same issue.
Is there a fix for this issue?
I'm wondering the same thing. This is a major issue for me as I cannot load any templates for my karma tests.
Hmm, effectively, the relativeness of a path seems to be forced here: https://github.com/karma-runner/karma-ng-html2js-preprocessor/blob/60d0ce66a561ab0f7390a2a11446797abc9bb9ed/lib/html2js.js#L38 without much room of overriding this logic.
@vojtajina do you happen to remember why this logic was put in place? Should we make it less "radical" / configurable?
If the relative path is best practice, could there at least be a 'forceAbsolute' option or something?