From 53d6b4ca047bed2f206bbbe0cce57b6b7e5c6088 Mon Sep 17 00:00:00 2001 From: Matteo Agosti Date: Tue, 23 Oct 2012 16:05:27 +0200 Subject: [PATCH] Supporting custom template extension Fix missing escape --- bin/handlebars | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/handlebars b/bin/handlebars index 7a2fc1ca..f83901dd 100755 --- a/bin/handlebars +++ b/bin/handlebars @@ -42,6 +42,12 @@ var optimist = require('optimist') 'type': 'string', 'description': 'Template root. Base value that will be stripped from template names.', 'alias': 'root' + }, + 'e': { + 'type': 'string', + 'description': 'Template extension.', + 'alias': 'extension', + 'default': 'handlebars' } }) @@ -87,6 +93,9 @@ if (argv.known) { } } +// Build file extension pattern +var extension = new RegExp('\\.' + argv.extension + '$'); + var output = []; if (!argv.simple) { if (argv.amd) { @@ -103,7 +112,7 @@ function processTemplate(template, root) { fs.readdirSync(template).map(function(file) { var path = template + '/' + file; - if (/\.handlebars$/.test(path) || fs.statSync(path).isDirectory()) { + if (extension.test(path) || fs.statSync(path).isDirectory()) { processTemplate(path, root || template); } }); @@ -121,7 +130,7 @@ function processTemplate(template, root) { } else if (template.indexOf(root) === 0) { template = template.substring(root.length+1); } - template = template.replace(/\.handlebars$/, ''); + template = template.replace(extension, ''); if (argv.simple) { output.push(handlebars.precompile(data, options) + '\n');