Adding partial precompilation

Also allowing to compile based on data getting passed in
This commit is contained in:
Brian Kaull
2012-11-26 11:51:53 -08:00
parent bd04901454
commit cbfe84f1a9
+17 -1
View File
@@ -48,6 +48,16 @@ var optimist = require('optimist')
'type': 'string',
'description': 'Template root. Base value that will be stripped from template names.',
'alias': 'root'
},
'p' : {
'type': 'boolean',
'description': 'Compiling a partial template',
'alias': 'partial'
},
'd' : {
'type': 'boolean',
'description': 'Include data when compiling',
'alias': 'data'
}
})
@@ -123,7 +133,11 @@ function processTemplate(template, root) {
knownHelpersOnly: argv.o
};
// Clean the template name
if (argv.data) {
options.data = true;
}
// Clean the template name
if (!root) {
template = basename(template);
} else if (template.indexOf(root) === 0) {
@@ -133,6 +147,8 @@ function processTemplate(template, root) {
if (argv.simple) {
output.push(handlebars.precompile(data, options) + '\n');
} else if (argv.partial) {
output.push('Handlebars.partials[\'' + template + '\'] = template(' + handlebars.precompile(data, options) + ');\n');
} else {
output.push('templates[\'' + template + '\'] = template(' + handlebars.precompile(data, options) + ');\n');
}