Make getFunctionSource support number values for indent in build.js.

Former-commit-id: 5f977d8058f6773fdffa09f01a59135e9ea3337a
This commit is contained in:
John-David Dalton
2013-06-30 10:49:55 -07:00
parent 51230f21f5
commit 6be64b363c

View File

@@ -783,7 +783,7 @@
}
var filePath = path.join(directory, filename),
text = fs.readFileSync(filePath, 'utf8'),
precompiled = cleanupCompiled(getFunctionSource(_.template(text, null, options))),
precompiled = cleanupCompiled(getFunctionSource(_.template(text, null, options), 2)),
prop = filename.replace(/\..*$/, '');
source.push(" templates['" + prop.replace(/['\n\r\t]/g, '\\$&') + "'] = " + precompiled + ';', '');
@@ -1057,13 +1057,15 @@
*
* @private
* @param {Function} func The function to process.
* @param {String} indent The function indent.
* @param {Number|String} [indent=0] The level to indent.
* @returns {String} Returns the formatted source.
*/
function getFunctionSource(func, indent) {
var source = func.source || (func + '');
if (indent == null) {
indent = ' ';
indent || (indent = '');
if (typeof indent == 'number') {
indent = Array(indent + 1).join(' ');
}
// format leading whitespace
return source.replace(/\n(?:.*)/g, function(match, index) {