From db7354ab722ddef6dac76efc4879090631f5b610 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 17 Jul 2013 08:07:46 -0700 Subject: [PATCH] Add `imports` option docs to `_.template`. Former-commit-id: 4ac5d64b0dae3068d07474beabed7fd5702da9a2 --- dist/lodash.compat.js | 47 ++++--- dist/lodash.compat.min.js | 68 +++++----- dist/lodash.js | 52 ++++---- dist/lodash.min.js | 6 +- dist/lodash.underscore.js | 31 +++-- dist/lodash.underscore.min.js | 36 +++--- doc/README.md | 228 +++++++++++++++++----------------- lodash.js | 17 ++- 8 files changed, 259 insertions(+), 226 deletions(-) diff --git a/dist/lodash.compat.js b/dist/lodash.compat.js index 0bb93da91..6f8995f80 100644 --- a/dist/lodash.compat.js +++ b/dist/lodash.compat.js @@ -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) { %>
  • <%= name %>
  • <% }); %>'; - * _.template(list, { 'people': ['moe', 'larry'] }); - * // => '
  • moe
  • larry
  • ' - * * // using the "escape" delimiter to escape HTML in data property values * _.template('<%- value %>', { 'value': '