karma-ng-html2js-preprocessor icon indicating copy to clipboard operation
karma-ng-html2js-preprocessor copied to clipboard

prependPrefix and cacheIdFromPath doesn't allow absolute paths

Open ivanbreet opened this issue 12 years ago • 6 comments

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

ivanbreet avatar Oct 11 '13 12:10 ivanbreet

Same issue with html2js task ! :) Would be great if that could work.

mica16 avatar Oct 23 '13 14:10 mica16

Subscribing. Having the exact same issue.

eriktoyra avatar Apr 10 '14 14:04 eriktoyra

Is there a fix for this issue?

protherj avatar Jun 25 '14 23:06 protherj

I'm wondering the same thing. This is a major issue for me as I cannot load any templates for my karma tests.

richiepreece avatar Oct 17 '14 15:10 richiepreece

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?

pkozlowski-opensource avatar Oct 17 '14 18:10 pkozlowski-opensource

If the relative path is best practice, could there at least be a 'forceAbsolute' option or something?

richiepreece avatar Oct 17 '14 19:10 richiepreece