karma-runner/karma-ng-html2js-preprocessor — pull request #54 by loganetherton (2014-12-05 22:20:04+00:00)
Title: Added dynamic replacement of string in prefix/suffix parsing

I found that I was unable to successfully create the template cache values for directives existing in different directories which are unparseable by the standard stripPrefix and prependPrefix options. For example, I had directives in:

'packages/custom/recentprojects/public/views/directiveTemplates/recent-projects.html'
and
'packages/users/public/views/directiveTemplates/team-members.html'

These needed to be turned into:

'recentprojects/views/directiveTemplates/recent-projects.html'
and
'users/views/directiveTemplates/recent-projects.html'

So, I had to strip out everything before public, and then insert prefixes which are different. Since reinsertion of the package name was required, I wrote up a quick regex fix that would allow that to happen. It works as follows:

stripPrefix: '.*/(.*)/public/views/directiveTemplates/',
prependPrefix: '{$1}/views/directiveTemplates/',

With {$1} being the first capturing subgroup, {$2} being the second, etc.

Hopefully this can help someone.