Template relinking leavers partials behind
Closed this issue · 4 comments
One minor niggle I found out, you might want to fix at some point (not critical), or if someone else needs this.
When using options.template, the template.hbs relinks ok, but partials stay linked to livingCSS/template directory.
It's a minor hassle, but e.g. for me, the need to relink template comes from need to keep all source files (including templates) in one location.
I fixed this now on my install by throwing in this code:
//Define path to Handlebars partials based on path to template
//So defaultPartials is always always grounded on path of options.template
var pathToTemplate = options.template.substring(0, options.template.lastIndexOf('/'));
defaultPartials = path.join(pathToTemplate, '/partials/*.hbs')
//console.log(defaultPartials)
Just after options.template is checked (on index.js, line 88). But, there is probably more elegant way to accomplish same :-)
When you say relink, do you mean you have your own directory structure that you want the partials loaded from? So you're structure looks something like this:
template/
template.hbs
partials/
partial.hbs
And you want your template and partials to load from there?
Exactly.
In the preprocess
option you can load your partials from your own directory and override the ones in the default partials directory.
preprocess: function(context, template, Handlebars) {
utils.readFileGlobs(defaultPartials, function(data, file) {
// make the name of the partial the name of the file
var partialName = path.basename(file, path.extname(file));
Handlebars.registerPartial(partialName, data);
})
}
Ok. I thought that I missed something obvious.