MCPcopy Index your code
hub / github.com/deployd/deployd / template

Function template

test-app/public/sinon.js:25396–25502  ·  view source on GitHub ↗

* Creates a compiled template function that can interpolate data properties * in "interpolate" delimiters, HTML-escape interpolated data properties in * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data * properties may be accessed as free variable

(string, options, guard)

Source from the content-addressed store, hash-verified

25394 * ');
25395 */
25396 function template(string, options, guard) {
25397 // Based on John Resig's `tmpl` implementation
25398 // (http://ejohn.org/blog/javascript-micro-templating/)
25399 // and Laura Doktorova's doT.js (https://github.com/olado/doT).
25400 var settings = lodash.templateSettings;
25401
25402 if (guard && isIterateeCall(string, options, guard)) {
25403 options = undefined;
25404 }
25405 string = toString(string);
25406 options = assignInWith({}, options, settings, customDefaultsAssignIn);
25407
25408 var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
25409 importsKeys = keys(imports),
25410 importsValues = baseValues(imports, importsKeys);
25411
25412 var isEscaping,
25413 isEvaluating,
25414 index = 0,
25415 interpolate = options.interpolate || reNoMatch,
25416 source = "__p += '";
25417
25418 // Compile the regexp to match each delimiter.
25419 var reDelimiters = RegExp(
25420 (options.escape || reNoMatch).source + '|' +
25421 interpolate.source + '|' +
25422 (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
25423 (options.evaluate || reNoMatch).source + '|$'
25424 , 'g');
25425
25426 // Use a sourceURL for easier debugging.
25427 var sourceURL = '//# sourceURL=' +
25428 ('sourceURL' in options
25429 ? options.sourceURL
25430 : ('lodash.templateSources[' + (++templateCounter) + ']')
25431 ) + '\n';
25432
25433 string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
25434 interpolateValue || (interpolateValue = esTemplateValue);
25435
25436 // Escape characters that can't be included in string literals.
25437 source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
25438
25439 // Replace delimiters with snippets.
25440 if (escapeValue) {
25441 isEscaping = true;
25442 source += "' +\n__e(" + escapeValue + ") +\n'";
25443 }
25444 if (evaluateValue) {
25445 isEvaluating = true;
25446 source += "';\n" + evaluateValue + ";\n__p += '";
25447 }
25448 if (interpolateValue) {
25449 source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
25450 }
25451 index = offset + match.length;
25452
25453 // The JS engine embedded in Adobe products needs `match` returned in

Callers

nothing calls this directly

Calls 5

isIterateeCallFunction · 0.85
keysFunction · 0.85
baseValuesFunction · 0.85
toStringFunction · 0.70
isErrorFunction · 0.70

Tested by

no test coverage detected