-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue when precompile handlebars template using AMD pattern work with requirejs #528
Comments
We need to update the bin script to look at the number of templates involved, not the number of arguments. |
yes, I found the reason that because the target I try to compile is a directory if (argv.simple) {
output.push(handlebars.precompile(data, options) + '\n');
} else if (argv.partial) {
if(argv.amd && argv._.length == 1){ output.push('return '); }
output.push('Handlebars.partials[\'' + template + '\'] = template(' + handlebars.precompile(data, options) + ');\n');
} else {
console.dir(argv);
if(argv.amd && argv._.length == 1){ output.push('return '); }
output.push('templates[\'' + template + '\'] = template(' + handlebars.precompile(data, options) + ');\n');
} the argv._ is still 1, I think what the author try to archieve is that when there is only one file, then return the templates, if the file is greater than 1, then didn't return, I think we could add a counter when read the file from the directory, like you said , look at the number of templates involved, not the number of arguments |
I'm trying to fix that on my local machine, and will ask for a pull request after I fix that |
I believe this is the same issue as #517 |
Hi kpdecker, var files = [];
getFiles(template, root,files);
argv.fileCount = files.length;
function getFiles(template,root,result){
var stat = fs.statSync(template);
if(stat.isDirectory()){
fs.readdirSync(template).map(function(file){
var path = template + '/'+file;
if(extension.test(path) || fs.statSync(path).isDirectory()){
getFiles(path, root || template,result);
}
})
}else{
result.push(template);
}
}
if (argv.simple) {
output.push(handlebars.precompile(data, options) + '\n');
} else if (argv.partial) {
if(argv.amd && argv.fileCount.length == 1){ output.push('return '); }
output.push('Handlebars.partials[\'' + template + '\'] = template(' + handlebars.precompile(data, options) + ');\n');
} else {
//console.dir(argv);
if(argv.amd && argv.fileCount.length == 1){ output.push('return '); }
output.push('templates[\'' + template + '\'] = template(' + handlebars.precompile(data, options) + ');\n');
} |
Can you open a pull request and we can review it there? |
Fixed by #533 |
when precompile several templates into my template.js with amd pattern, the compiled js seems not correct.
I was using the latest Handlebars.cmd to compile the templates.
command: handlebars .\templates -f .\public\scripts\app\templates.js -a -n Handlebars.tpl
it just return the first template so I can't get rest template. I need to manually remove the return to workaround
The text was updated successfully, but these errors were encountered: