Skip to content
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

Fix bug Issue #528 #532

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions bin/handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ if (argv.known) {
var extension = argv.extension.replace(/[\\^$*+?.():=!|{}\-\[\]]/g, function(arg) { return '\\' + arg; });
extension = new RegExp('\\.' + extension + '$');

var files = [];
getFiles(template, root,files);
argv.fileCount = files.length;

function getFiles(template,root,result){
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get total files from template before processTemplate

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);
}
}

var output = [];
if (!argv.simple) {
if (argv.amd) {
Expand Down Expand Up @@ -168,10 +186,10 @@ function processTemplate(template, root) {
if (argv.simple) {
output.push(handlebars.precompile(data, options) + '\n');
} else if (argv.partial) {
if(argv.amd && argv._.length == 1){ output.push('return '); }
if(argv.amd && argv.fileCount.length == 1){ output.push('return '); }
output.push('Handlebars.partials[\'' + template + '\'] = template(' + handlebars.precompile(data, options) + ');\n');
} else {
if(argv.amd && argv._.length == 1){ output.push('return '); }
if(argv.amd && argv.fileCount.length == 1){ output.push('return '); }
output.push('templates[\'' + template + '\'] = template(' + handlebars.precompile(data, options) + ');\n');
}
}
Expand Down