mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Remove references to _.
This commit is contained in:
41
template.js
41
template.js
@@ -32,9 +32,9 @@ const reUnescapedString = /['\n\r\u2028\u2029\\]/g;
|
||||
* in "interpolate" delimiters, HTML-escape interpolated data properties in
|
||||
* "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
|
||||
* properties may be accessed as free variables in the template. If a setting
|
||||
* object is given, it takes precedence over `_.templateSettings` values.
|
||||
* object is given, it takes precedence over `templateSettings` values.
|
||||
*
|
||||
* **Note:** In the development build `_.template` utilizes
|
||||
* **Note:** In the development build `template` utilizes
|
||||
* [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
|
||||
* for easier debugging.
|
||||
*
|
||||
@@ -46,70 +46,69 @@ const reUnescapedString = /['\n\r\u2028\u2029\\]/g;
|
||||
*
|
||||
* @static
|
||||
* @since 0.1.0
|
||||
* @memberOf _
|
||||
* @category String
|
||||
* @param {string} [string=''] The template string.
|
||||
* @param {Object} [options={}] The options object.
|
||||
* @param {RegExp} [options.escape=_.templateSettings.escape]
|
||||
* @param {RegExp} [options.escape=templateSettings.escape]
|
||||
* The HTML "escape" delimiter.
|
||||
* @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
|
||||
* @param {RegExp} [options.evaluate=templateSettings.evaluate]
|
||||
* The "evaluate" delimiter.
|
||||
* @param {Object} [options.imports=_.templateSettings.imports]
|
||||
* @param {Object} [options.imports=templateSettings.imports]
|
||||
* An object to import into the template as free variables.
|
||||
* @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
|
||||
* @param {RegExp} [options.interpolate=templateSettings.interpolate]
|
||||
* The "interpolate" delimiter.
|
||||
* @param {string} [options.sourceURL='templateSources[n]']
|
||||
* The sourceURL of the compiled template.
|
||||
* @param {string} [options.variable='obj']
|
||||
* The data object variable name.
|
||||
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
|
||||
* @param- {Object} [guard] Enables use as an iteratee for methods like `map`.
|
||||
* @returns {Function} Returns the compiled template function.
|
||||
* @example
|
||||
*
|
||||
* // Use the "interpolate" delimiter to create a compiled template.
|
||||
* var compiled = _.template('hello <%= user %>!');
|
||||
* var compiled = template('hello <%= user %>!');
|
||||
* compiled({ 'user': 'fred' });
|
||||
* // => 'hello fred!'
|
||||
*
|
||||
* // Use the HTML "escape" delimiter to escape data property values.
|
||||
* var compiled = _.template('<b><%- value %></b>');
|
||||
* var compiled = template('<b><%- value %></b>');
|
||||
* compiled({ 'value': '<script>' });
|
||||
* // => '<b><script></b>'
|
||||
*
|
||||
* // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
|
||||
* var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
|
||||
* var compiled = template('<% forEach(users, function(user) { %><li><%- user %></li><% }); %>');
|
||||
* compiled({ 'users': ['fred', 'barney'] });
|
||||
* // => '<li>fred</li><li>barney</li>'
|
||||
*
|
||||
* // Use the internal `print` function in "evaluate" delimiters.
|
||||
* var compiled = _.template('<% print("hello " + user); %>!');
|
||||
* var compiled = template('<% print("hello " + user); %>!');
|
||||
* compiled({ 'user': 'barney' });
|
||||
* // => 'hello barney!'
|
||||
*
|
||||
* // Use the ES template literal delimiter as an "interpolate" delimiter.
|
||||
* // Disable support by replacing the "interpolate" delimiter.
|
||||
* var compiled = _.template('hello ${ user }!');
|
||||
* var compiled = template('hello ${ user }!');
|
||||
* compiled({ 'user': 'pebbles' });
|
||||
* // => 'hello pebbles!'
|
||||
*
|
||||
* // Use backslashes to treat delimiters as plain text.
|
||||
* var compiled = _.template('<%= "\\<%- value %\\>" %>');
|
||||
* var compiled = template('<%= "\\<%- value %\\>" %>');
|
||||
* compiled({ 'value': 'ignored' });
|
||||
* // => '<%- value %>'
|
||||
*
|
||||
* // Use the `imports` option to import `jQuery` as `jq`.
|
||||
* var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
|
||||
* var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
|
||||
* var compiled = template(text, { 'imports': { 'jq': jQuery } });
|
||||
* compiled({ 'users': ['fred', 'barney'] });
|
||||
* // => '<li>fred</li><li>barney</li>'
|
||||
*
|
||||
* // Use the `sourceURL` option to specify a custom sourceURL for the template.
|
||||
* var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
|
||||
* var compiled = template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
|
||||
* compiled(data);
|
||||
* // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
|
||||
*
|
||||
* // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
|
||||
* var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
|
||||
* var compiled = template('hi <%= data.user %>!', { 'variable': 'data' });
|
||||
* compiled.source;
|
||||
* // => function(data) {
|
||||
* // var __t, __p = '';
|
||||
@@ -118,8 +117,8 @@ const reUnescapedString = /['\n\r\u2028\u2029\\]/g;
|
||||
* // }
|
||||
*
|
||||
* // Use custom template delimiters.
|
||||
* _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
||||
* var compiled = _.template('hello {{ user }}!');
|
||||
* templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
||||
* var compiled = template('hello {{ user }}!');
|
||||
* compiled({ 'user': 'mustache' });
|
||||
* // => 'hello mustache!'
|
||||
*
|
||||
@@ -127,7 +126,7 @@ const reUnescapedString = /['\n\r\u2028\u2029\\]/g;
|
||||
* // line numbers in error messages and stack traces.
|
||||
* fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
|
||||
* var JST = {\
|
||||
* "main": ' + _.template(mainText).source + '\
|
||||
* "main": ' + template(mainText).source + '\
|
||||
* };\
|
||||
* ');
|
||||
*/
|
||||
@@ -135,7 +134,7 @@ function template(string, options, guard) {
|
||||
// Based on John Resig's `tmpl` implementation
|
||||
// (http://ejohn.org/blog/javascript-micro-templating/)
|
||||
// and Laura Doktorova's doT.js (https://github.com/olado/doT).
|
||||
let settings = templateSettings.imports._.templateSettings || templateSettings;
|
||||
let settings = templateSettings.imports.templateSettings || templateSettings;
|
||||
|
||||
if (guard && isIterateeCall(string, options, guard)) {
|
||||
options = undefined;
|
||||
|
||||
Reference in New Issue
Block a user