mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Merge pull request #542 from braddunbar/template-concat
_.template Uses Concatenation
This commit is contained in:
@@ -957,25 +957,26 @@
|
|||||||
// Compile the template source, taking care to escape characters that
|
// Compile the template source, taking care to escape characters that
|
||||||
// cannot be included in a string literal and then unescape them in code
|
// cannot be included in a string literal and then unescape them in code
|
||||||
// blocks.
|
// blocks.
|
||||||
var source = "__p.push('" + text
|
var source = "__p+='" + text
|
||||||
.replace(escaper, function(match) {
|
.replace(escaper, function(match) {
|
||||||
return '\\' + escapes[match];
|
return '\\' + escapes[match];
|
||||||
})
|
})
|
||||||
.replace(settings.escape || noMatch, function(match, code) {
|
.replace(settings.escape || noMatch, function(match, code) {
|
||||||
return "',\n_.escape(" + unescape(code) + "),\n'";
|
return "'+\n_.escape(" + unescape(code) + ")+\n'";
|
||||||
})
|
})
|
||||||
.replace(settings.interpolate || noMatch, function(match, code) {
|
.replace(settings.interpolate || noMatch, function(match, code) {
|
||||||
return "',\n" + unescape(code) + ",\n'";
|
return "'+\n(" + unescape(code) + ")+\n'";
|
||||||
})
|
})
|
||||||
.replace(settings.evaluate || noMatch, function(match, code) {
|
.replace(settings.evaluate || noMatch, function(match, code) {
|
||||||
return "');\n" + unescape(code) + "\n;__p.push('";
|
return "';\n" + unescape(code) + "\n;__p+='";
|
||||||
}) + "');\n";
|
}) + "';\n";
|
||||||
|
|
||||||
// If a variable is not specified, place data values in local scope.
|
// If a variable is not specified, place data values in local scope.
|
||||||
if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
|
if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
|
||||||
|
|
||||||
source = 'var __p=[],print=function(){__p.push.apply(__p,arguments);};\n' +
|
source = "var __p='';" +
|
||||||
source + "return __p.join('');\n";
|
"var print=function(){__p+=Array.prototype.join.call(arguments, '')};\n" +
|
||||||
|
source + "return __p;\n";
|
||||||
|
|
||||||
var render = new Function(settings.variable || 'obj', '_', source);
|
var render = new Function(settings.variable || 'obj', '_', source);
|
||||||
if (data) return render(data, _);
|
if (data) return render(data, _);
|
||||||
@@ -986,7 +987,7 @@
|
|||||||
// Provide the compiled function source as a convenience for build time
|
// Provide the compiled function source as a convenience for build time
|
||||||
// precompilation.
|
// precompilation.
|
||||||
template.source = 'function(' + (settings.variable || 'obj') + '){\n' +
|
template.source = 'function(' + (settings.variable || 'obj') + '){\n' +
|
||||||
source + '\n}';
|
source + '}';
|
||||||
|
|
||||||
return template;
|
return template;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user