Open ghost opened 10 years ago
I find this inconvenient as well. I'm surprised no one else has commented on this.
In case anyone is looking for a quick workaround for this, I decided to just use this plugin to fix the paths: https://github.com/erickrdch/grunt-string-replace
So you just run the string-replace plugin after the JST plugin. Going with @jcochran 's example, you just do something like this:
'string-replace': {
jst: {
files: {
'www/javascripts/templates.js': 'www/javascripts/templates.js'
},
options: {
replacements: [{
pattern: /www\/javascripts\/templates/ig,
replacement: 'templates'
}]
}
}
},
Yes, I went with something very similar.
Sent from my iPhone
On Sep 15, 2014, at 12:06 PM, "Travis Wimer" notifications@github.com<mailto:notifications@github.com> wrote:
In case anyone is looking for a quick workaround for this, I decided to just use this plugin to fix the paths: https://github.com/erickrdch/grunt-string-replace
So you just run the string-replace plugin after the JST plugin. Going with @jcochranhttps://github.com/jcochran 's example, you just do something like this:
'string-replace': { jst: { files: { 'www/javascripts/templates.js': 'www/javascripts/templates.js' }, options: { replacements: [{ pattern: /www\/javascripts\/templates/ig, replacement: 'templates' }] } } },
— Reply to this email directly or view it on GitHubhttps://github.com/gruntjs/grunt-contrib-jst/issues/47#issuecomment-55622788.
You don't need a separate plugin for this. There is an option built right into this one, called processName
.
So you can do
jst: {
compile: {
options: {
processName: function(thatHugeFilepath){
return thatHugeFilepath.replace('/www/javascripts/templates/', 'templates');
}
}
}
}
Of course, you can just as easily use any other string function to transform your template names.
Thanks for explaining. That works perfectly.
I actually saw that option in the README, but it I found it rather unclear. The description mentions the JST
namespace, so I thought it was basically an alternative to the namespace
option that allowed you to use a function.
Rereading it now, it does make sense, but the wording could probably be clearer.
I am working on using grunt with a backbone/cordova (phonegap)...
It would be nice to have a "dest_path" and "include_ext" options so you could set the destination folder of the template and whether or not to include the extension of the file name in the template name.
Example:
The end result is that each template has "www/javascripts/templates/" before each templat name:
The new option would like look like:
and the end results would be:
So in backbone I can refer to the templates as such:
Clear as mud?
BTW, thanks for the work on this. It is going to save me a bunch of time. :+1: