Cleanup stored template names.
This commit is contained in:
+15
-3
@@ -21,6 +21,11 @@ var optimist = require('optimist')
|
|||||||
'type': 'boolean',
|
'type': 'boolean',
|
||||||
'description': 'Minimize output',
|
'description': 'Minimize output',
|
||||||
'alias': 'min'
|
'alias': 'min'
|
||||||
|
},
|
||||||
|
'r': {
|
||||||
|
'type': 'string',
|
||||||
|
'description': 'Template root. Base value that will be stripped from template names.',
|
||||||
|
'alias': 'root'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -41,6 +46,7 @@ var optimist = require('optimist')
|
|||||||
|
|
||||||
var fs = require('fs'),
|
var fs = require('fs'),
|
||||||
handlebars = require('../lib/handlebars'),
|
handlebars = require('../lib/handlebars'),
|
||||||
|
basename = require('path').basename,
|
||||||
uglify = require('uglify-js');
|
uglify = require('uglify-js');
|
||||||
|
|
||||||
var argv = optimist.argv,
|
var argv = optimist.argv,
|
||||||
@@ -58,7 +64,7 @@ if (argv.known) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var output = ['(function() {\n var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\n'];
|
var output = ['(function() {\n var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};\n'];
|
||||||
function processTemplate(template) {
|
function processTemplate(template, root) {
|
||||||
var path = template,
|
var path = template,
|
||||||
stat = fs.statSync(path);
|
stat = fs.statSync(path);
|
||||||
if (stat.isDirectory()) {
|
if (stat.isDirectory()) {
|
||||||
@@ -66,7 +72,7 @@ function processTemplate(template) {
|
|||||||
var path = template + '/' + file;
|
var path = template + '/' + file;
|
||||||
|
|
||||||
if (/\.handlebars$/.test(path) || fs.statSync(path).isDirectory()) {
|
if (/\.handlebars$/.test(path) || fs.statSync(path).isDirectory()) {
|
||||||
processTemplate(path);
|
processTemplate(path, root || template);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -77,14 +83,20 @@ function processTemplate(template) {
|
|||||||
knownHelpersOnly: argv.o
|
knownHelpersOnly: argv.o
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Clean the template name
|
||||||
|
if (!root) {
|
||||||
|
template = basename(template);
|
||||||
|
} else if (template.indexOf(root) === 0) {
|
||||||
|
template = template.substring(root.length+1);
|
||||||
}
|
}
|
||||||
|
template = template.replace(/\.handlebars$/, '');
|
||||||
|
|
||||||
output.push('templates[\'' + template + '\'] = template(' + handlebars.precompile(data, options) + ');\n');
|
output.push('templates[\'' + template + '\'] = template(' + handlebars.precompile(data, options) + ');\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
argv._.forEach(function(template) {
|
argv._.forEach(function(template) {
|
||||||
processTemplate(template);
|
processTemplate(template, argv.root);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Output the content
|
// Output the content
|
||||||
|
|||||||
Reference in New Issue
Block a user