Add imports option docs to _.template.

Former-commit-id: 4ac5d64b0dae3068d07474beabed7fd5702da9a2
This commit is contained in:
John-David Dalton
2013-07-17 08:07:46 -07:00
parent 34396dbbec
commit db7354ab72
8 changed files with 259 additions and 226 deletions

47
dist/lodash.compat.js vendored
View File

@@ -443,7 +443,7 @@
// Avoid issues with some ES3 environments that attempt to use values, named
// after built-in constructors like `Object`, for the creation of literals.
// ES5 clears this up by stating that literals must use built-in constructors.
// See http://es5.github.com/#x11.1.5.
// See http://es5.github.io/#x11.1.5.
context = context ? _.defaults(window.Object(), context, _.pick(window, contextProps)) : window;
/** Native constructor references */
@@ -1060,7 +1060,7 @@
function bound() {
// `Function#bind` spec
// http://es5.github.com/#x15.3.4.5
// http://es5.github.io/#x15.3.4.5
var args = arguments,
thisBinding = isPartial ? this : thisArg;
@@ -1077,7 +1077,7 @@
thisBinding = createObject(func.prototype);
// mimic the constructor's `return` behavior
// http://es5.github.com/#x13.2.2
// http://es5.github.io/#x13.2.2
var result = func.apply(thisBinding, args);
return isObject(result) ? result : thisBinding;
}
@@ -1105,6 +1105,7 @@
// data properties
data.shadowedProps = shadowedProps;
// iterator options
data.array = data.bottom = data.loop = data.top = '';
data.init = 'iterable';
@@ -1133,7 +1134,7 @@
// return the compiled function
return factory(
errorClass, errorProto, hasOwnProperty, indicatorObject, isArguments,
isArray, isString, keys, lodash, objectProto, objectTypes, nonEnumProps,
isArray, isString, data.useKeys && keys, lodash, objectProto, objectTypes, nonEnumProps,
stringClass, stringProto, toString
);
}
@@ -1296,7 +1297,8 @@
'args': 'object',
'init': '[]',
'top': 'if (!(objectTypes[typeof object])) return result',
'loop': 'result.push(index)'
'loop': 'result.push(index)',
'useKeys': false
});
/**
@@ -1914,12 +1916,12 @@
// exit early for unlike primitive values
if (a === a &&
(!a || (type != 'function' && type != 'object')) &&
(!b || (otherType != 'function' && otherType != 'object'))) {
!(a && objectTypes[type]) &&
!(b && objectTypes[otherType])) {
return false;
}
// exit early for `null` and `undefined`, avoiding ES3's Function#call behavior
// http://es5.github.com/#x15.3.4.4
// http://es5.github.io/#x15.3.4.4
if (a == null || b == null) {
return a === b;
}
@@ -1952,7 +1954,7 @@
case regexpClass:
case stringClass:
// coerce regexes to strings (http://es5.github.com/#x15.10.6.4)
// coerce regexes to strings (http://es5.github.io/#x15.10.6.4)
// treat string primitives and their corresponding object instances as equal
return a == String(b);
}
@@ -1980,7 +1982,7 @@
}
// assume cyclic structures are equal
// the algorithm for detecting cyclic structures is adapted from ES 5.1
// section 15.12.3, abstract operation `JO` (http://es5.github.com/#x15.12.3)
// section 15.12.3, abstract operation `JO` (http://es5.github.io/#x15.12.3)
var initedStack = !stackA;
stackA || (stackA = getArray());
stackB || (stackB = getArray());
@@ -2056,7 +2058,7 @@
* Checks if `value` is, or can be coerced to, a finite number.
*
* Note: This is not the same as native `isFinite`, which will return true for
* booleans and empty strings. See http://es5.github.com/#x15.1.2.5.
* booleans and empty strings. See http://es5.github.io/#x15.1.2.5.
*
* @static
* @memberOf _
@@ -2129,7 +2131,7 @@
*/
function isObject(value) {
// check if the value is the ECMAScript language type of Object
// http://es5.github.com/#x8
// http://es5.github.io/#x8
// and avoid a V8 bug
// http://code.google.com/p/v8/issues/detail?id=2291
return !!(value && objectTypes[typeof value]);
@@ -2139,7 +2141,7 @@
* Checks if `value` is `NaN`.
*
* Note: This is not the same as native `isNaN`, which will return `true` for
* `undefined` and other values. See http://es5.github.com/#x15.1.2.4.
* `undefined` and other values. See http://es5.github.io/#x15.1.2.4.
*
* @static
* @memberOf _
@@ -5243,7 +5245,7 @@
* `value` is a hexadecimal, in which case a `radix` of `16` is used.
*
* Note: This method avoids differences in native ES3 and ES5 `parseInt`
* implementations. See http://es5.github.com/#E.
* implementations. See http://es5.github.io/#E.
*
* @static
* @memberOf _
@@ -5349,6 +5351,7 @@
* @param {Object} options The options object.
* escape - The "escape" delimiter regexp.
* evaluate - The "evaluate" delimiter regexp.
* imports - An object of properties to import into the compiled template as local variables.
* interpolate - The "interpolate" delimiter regexp.
* sourceURL - The sourceURL of the template's compiled source.
* variable - The data object variable name.
@@ -5361,14 +5364,15 @@
* compiled({ 'name': 'moe' });
* // => 'hello moe'
*
* var list = '<% _.forEach(people, function(name) { %><li><%= name %></li><% }); %>';
* _.template(list, { 'people': ['moe', 'larry'] });
* // => '<li>moe</li><li>larry</li>'
*
* // using the "escape" delimiter to escape HTML in data property values
* _.template('<b><%- value %></b>', { 'value': '<script>' });
* // => '<b>&lt;script&gt;</b>'
*
* // using the "evaluate" delimiter to generate HTML
* var list = '<% _.forEach(people, function(name) { %><li><%= name %></li><% }); %>';
* _.template(list, { 'people': ['moe', 'larry'] });
* // => '<li>moe</li><li>larry</li>'
*
* // using the ES6 delimiter as an alternative to the default "interpolate" delimiter
* _.template('hello ${ name }', { 'name': 'curly' });
* // => 'hello curly'
@@ -5377,7 +5381,7 @@
* _.template('<% print("hello " + epithet); %>!', { 'epithet': 'stooge' });
* // => 'hello stooge!'
*
* // using custom template delimiters
* // using a custom template delimiters
* _.templateSettings = {
* 'interpolate': /{{([\s\S]+?)}}/g
* };
@@ -5385,6 +5389,11 @@
* _.template('hello {{ name }}!', { 'name': 'mustache' });
* // => 'hello mustache!'
*
* // using the `imports` option to import jQuery
* var list = '<% $.each(people, function(name) { %><li><%= name %></li><% }); %>';
* _.template(list, { 'people': ['moe', 'larry'] }, { 'imports': { '$': jQuery });
* // => '<li>moe</li><li>larry</li>'
*
* // using the `sourceURL` option to specify a custom sourceURL for the template
* var compiled = _.template('hello <%= name %>', null, { 'sourceURL': '/basic/greeting.jst' });
* compiled(data);