underscore-rails 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/underscore-rails/version.rb +1 -1
- data/vendor/assets/javascripts/underscore.js +60 -47
- metadata +3 -4
@@ -1,5 +1,5 @@
|
|
1
|
-
// Underscore.js 1.
|
2
|
-
// (c)
|
1
|
+
// Underscore.js 1.3.0
|
2
|
+
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
|
3
3
|
// Underscore is freely distributable under the MIT license.
|
4
4
|
// Portions of Underscore are inspired or borrowed from Prototype,
|
5
5
|
// Oliver Steele's Functional, and John Resig's Micro-Templating.
|
@@ -48,26 +48,21 @@
|
|
48
48
|
// Create a safe reference to the Underscore object for use below.
|
49
49
|
var _ = function(obj) { return new wrapper(obj); };
|
50
50
|
|
51
|
-
// Export the Underscore object for **Node.js
|
52
|
-
// backwards-compatibility for the old `require()` API. If we're
|
53
|
-
//
|
51
|
+
// Export the Underscore object for **Node.js**, with
|
52
|
+
// backwards-compatibility for the old `require()` API. If we're in
|
53
|
+
// the browser, add `_` as a global object via a string identifier,
|
54
|
+
// for Closure Compiler "advanced" mode.
|
54
55
|
if (typeof exports !== 'undefined') {
|
55
56
|
if (typeof module !== 'undefined' && module.exports) {
|
56
57
|
exports = module.exports = _;
|
57
58
|
}
|
58
59
|
exports._ = _;
|
59
|
-
} else if (typeof define === 'function' && define.amd) {
|
60
|
-
// Register as a named module with AMD.
|
61
|
-
define('underscore', function() {
|
62
|
-
return _;
|
63
|
-
});
|
64
60
|
} else {
|
65
|
-
// Exported as a string, for Closure Compiler "advanced" mode.
|
66
61
|
root['_'] = _;
|
67
62
|
}
|
68
63
|
|
69
64
|
// Current version.
|
70
|
-
_.VERSION = '1.
|
65
|
+
_.VERSION = '1.3.0';
|
71
66
|
|
72
67
|
// Collection Functions
|
73
68
|
// --------------------
|
@@ -94,20 +89,21 @@
|
|
94
89
|
|
95
90
|
// Return the results of applying the iterator to each element.
|
96
91
|
// Delegates to **ECMAScript 5**'s native `map` if available.
|
97
|
-
_.map = function(obj, iterator, context) {
|
92
|
+
_.map = _.collect = function(obj, iterator, context) {
|
98
93
|
var results = [];
|
99
94
|
if (obj == null) return results;
|
100
95
|
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
|
101
96
|
each(obj, function(value, index, list) {
|
102
97
|
results[results.length] = iterator.call(context, value, index, list);
|
103
98
|
});
|
99
|
+
if (obj.length === +obj.length) results.length = obj.length;
|
104
100
|
return results;
|
105
101
|
};
|
106
102
|
|
107
103
|
// **Reduce** builds up a single result from a list of values, aka `inject`,
|
108
104
|
// or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
|
109
105
|
_.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
|
110
|
-
var initial =
|
106
|
+
var initial = arguments.length > 2;
|
111
107
|
if (obj == null) obj = [];
|
112
108
|
if (nativeReduce && obj.reduce === nativeReduce) {
|
113
109
|
if (context) iterator = _.bind(iterator, context);
|
@@ -121,20 +117,22 @@
|
|
121
117
|
memo = iterator.call(context, memo, value, index, list);
|
122
118
|
}
|
123
119
|
});
|
124
|
-
if (!initial) throw new TypeError(
|
120
|
+
if (!initial) throw new TypeError('Reduce of empty array with no initial value');
|
125
121
|
return memo;
|
126
122
|
};
|
127
123
|
|
128
124
|
// The right-associative version of reduce, also known as `foldr`.
|
129
125
|
// Delegates to **ECMAScript 5**'s native `reduceRight` if available.
|
130
126
|
_.reduceRight = _.foldr = function(obj, iterator, memo, context) {
|
127
|
+
var initial = arguments.length > 2;
|
131
128
|
if (obj == null) obj = [];
|
132
129
|
if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
|
133
130
|
if (context) iterator = _.bind(iterator, context);
|
134
|
-
return
|
131
|
+
return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
|
135
132
|
}
|
136
|
-
var reversed =
|
137
|
-
|
133
|
+
var reversed = _.toArray(obj).reverse();
|
134
|
+
if (context && !initial) iterator = _.bind(iterator, context);
|
135
|
+
return initial ? _.reduce(reversed, iterator, memo, context) : _.reduce(reversed, iterator);
|
138
136
|
};
|
139
137
|
|
140
138
|
// Return the first value which passes a truth test. Aliased as `detect`.
|
@@ -189,7 +187,7 @@
|
|
189
187
|
// Delegates to **ECMAScript 5**'s native `some` if available.
|
190
188
|
// Aliased as `any`.
|
191
189
|
var any = _.some = _.any = function(obj, iterator, context) {
|
192
|
-
iterator
|
190
|
+
iterator || (iterator = _.identity);
|
193
191
|
var result = false;
|
194
192
|
if (obj == null) return result;
|
195
193
|
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
|
@@ -215,7 +213,7 @@
|
|
215
213
|
_.invoke = function(obj, method) {
|
216
214
|
var args = slice.call(arguments, 2);
|
217
215
|
return _.map(obj, function(value) {
|
218
|
-
return (method
|
216
|
+
return (_.isFunction(method) ? method || value : value[method]).apply(value, args);
|
219
217
|
});
|
220
218
|
};
|
221
219
|
|
@@ -402,10 +400,11 @@
|
|
402
400
|
});
|
403
401
|
};
|
404
402
|
|
405
|
-
// Take the difference between one array and
|
403
|
+
// Take the difference between one array and a number of other arrays.
|
406
404
|
// Only the elements present in just the first array will remain.
|
407
|
-
_.difference = function(array
|
408
|
-
|
405
|
+
_.difference = function(array) {
|
406
|
+
var rest = _.flatten(slice.call(arguments, 1));
|
407
|
+
return _.filter(array, function(value){ return !_.include(rest, value); });
|
409
408
|
};
|
410
409
|
|
411
410
|
// Zip together multiple lists into a single array -- elements that share
|
@@ -432,7 +431,7 @@
|
|
432
431
|
return array[i] === item ? i : -1;
|
433
432
|
}
|
434
433
|
if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item);
|
435
|
-
for (i = 0, l = array.length; i < l; i++) if (array[i] === item) return i;
|
434
|
+
for (i = 0, l = array.length; i < l; i++) if (i in array && array[i] === item) return i;
|
436
435
|
return -1;
|
437
436
|
};
|
438
437
|
|
@@ -441,7 +440,7 @@
|
|
441
440
|
if (array == null) return -1;
|
442
441
|
if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item);
|
443
442
|
var i = array.length;
|
444
|
-
while (i--) if (array[i] === item) return i;
|
443
|
+
while (i--) if (i in array && array[i] === item) return i;
|
445
444
|
return -1;
|
446
445
|
};
|
447
446
|
|
@@ -579,7 +578,7 @@
|
|
579
578
|
// conditionally execute the original function.
|
580
579
|
_.wrap = function(func, wrapper) {
|
581
580
|
return function() {
|
582
|
-
var args = [func].concat(slice.call(arguments));
|
581
|
+
var args = [func].concat(slice.call(arguments, 0));
|
583
582
|
return wrapper.apply(this, args);
|
584
583
|
};
|
585
584
|
};
|
@@ -587,9 +586,9 @@
|
|
587
586
|
// Returns a function that is the composition of a list of functions, each
|
588
587
|
// consuming the return value of the function that follows.
|
589
588
|
_.compose = function() {
|
590
|
-
var funcs =
|
589
|
+
var funcs = arguments;
|
591
590
|
return function() {
|
592
|
-
var args =
|
591
|
+
var args = arguments;
|
593
592
|
for (var i = funcs.length - 1; i >= 0; i--) {
|
594
593
|
args = [funcs[i].apply(this, args)];
|
595
594
|
}
|
@@ -677,8 +676,8 @@
|
|
677
676
|
if (a._chain) a = a._wrapped;
|
678
677
|
if (b._chain) b = b._wrapped;
|
679
678
|
// Invoke a custom `isEqual` method if one is provided.
|
680
|
-
if (_.isFunction(a.isEqual)) return a.isEqual(b);
|
681
|
-
if (_.isFunction(b.isEqual)) return b.isEqual(a);
|
679
|
+
if (a.isEqual && _.isFunction(a.isEqual)) return a.isEqual(b);
|
680
|
+
if (b.isEqual && _.isFunction(b.isEqual)) return b.isEqual(a);
|
682
681
|
// Compare `[[Class]]` names.
|
683
682
|
var className = toString.call(a);
|
684
683
|
if (className != toString.call(b)) return false;
|
@@ -687,13 +686,11 @@
|
|
687
686
|
case '[object String]':
|
688
687
|
// Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
|
689
688
|
// equivalent to `new String("5")`.
|
690
|
-
return
|
689
|
+
return a == String(b);
|
691
690
|
case '[object Number]':
|
692
|
-
a = +a;
|
693
|
-
b = +b;
|
694
691
|
// `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
|
695
692
|
// other numeric values.
|
696
|
-
return a != a ? b != b : (a == 0 ? 1 / a == 1 / b : a == b);
|
693
|
+
return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
|
697
694
|
case '[object Date]':
|
698
695
|
case '[object Boolean]':
|
699
696
|
// Coerce dates and booleans to numeric primitive values. Dates are compared by their
|
@@ -733,7 +730,7 @@
|
|
733
730
|
}
|
734
731
|
} else {
|
735
732
|
// Objects with different constructors are not equivalent.
|
736
|
-
if (
|
733
|
+
if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false;
|
737
734
|
// Deep compare objects.
|
738
735
|
for (var key in a) {
|
739
736
|
if (hasOwnProperty.call(a, key)) {
|
@@ -786,11 +783,10 @@
|
|
786
783
|
};
|
787
784
|
|
788
785
|
// Is a given variable an arguments object?
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
} else {
|
786
|
+
_.isArguments = function(obj) {
|
787
|
+
return toString.call(obj) == '[object Arguments]';
|
788
|
+
};
|
789
|
+
if (!_.isArguments(arguments)) {
|
794
790
|
_.isArguments = function(obj) {
|
795
791
|
return !!(obj && hasOwnProperty.call(obj, 'callee'));
|
796
792
|
};
|
@@ -891,6 +887,11 @@
|
|
891
887
|
escape : /<%-([\s\S]+?)%>/g
|
892
888
|
};
|
893
889
|
|
890
|
+
// When customizing `templateSettings`, if you don't want to define an
|
891
|
+
// interpolation, evaluation or escaping regex, we need one that is
|
892
|
+
// guaranteed not to match.
|
893
|
+
var noMatch = /.^/;
|
894
|
+
|
894
895
|
// JavaScript micro-templating, similar to John Resig's implementation.
|
895
896
|
// Underscore templating handles arbitrary delimiters, preserves whitespace,
|
896
897
|
// and correctly escapes quotes within interpolated code.
|
@@ -900,22 +901,31 @@
|
|
900
901
|
'with(obj||{}){__p.push(\'' +
|
901
902
|
str.replace(/\\/g, '\\\\')
|
902
903
|
.replace(/'/g, "\\'")
|
903
|
-
.replace(c.escape, function(match, code) {
|
904
|
+
.replace(c.escape || noMatch, function(match, code) {
|
904
905
|
return "',_.escape(" + code.replace(/\\'/g, "'") + "),'";
|
905
906
|
})
|
906
|
-
.replace(c.interpolate, function(match, code) {
|
907
|
+
.replace(c.interpolate || noMatch, function(match, code) {
|
907
908
|
return "'," + code.replace(/\\'/g, "'") + ",'";
|
908
909
|
})
|
909
|
-
.replace(c.evaluate ||
|
910
|
+
.replace(c.evaluate || noMatch, function(match, code) {
|
910
911
|
return "');" + code.replace(/\\'/g, "'")
|
911
|
-
.replace(/[\r\n\t]/g, ' ')
|
912
|
+
.replace(/[\r\n\t]/g, ' ')
|
913
|
+
.replace(/\\\\/g, '\\') + ";__p.push('";
|
912
914
|
})
|
913
915
|
.replace(/\r/g, '\\r')
|
914
916
|
.replace(/\n/g, '\\n')
|
915
917
|
.replace(/\t/g, '\\t')
|
916
918
|
+ "');}return __p.join('');";
|
917
919
|
var func = new Function('obj', '_', tmpl);
|
918
|
-
|
920
|
+
if (data) return func(data, _);
|
921
|
+
return function(data) {
|
922
|
+
return func.call(this, data, _);
|
923
|
+
};
|
924
|
+
};
|
925
|
+
|
926
|
+
// Add a "chain" function, which will delegate to the wrapper.
|
927
|
+
_.chain = function(obj) {
|
928
|
+
return _(obj).chain();
|
919
929
|
};
|
920
930
|
|
921
931
|
// The OOP Wrapper
|
@@ -950,8 +960,11 @@
|
|
950
960
|
each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
|
951
961
|
var method = ArrayProto[name];
|
952
962
|
wrapper.prototype[name] = function() {
|
953
|
-
|
954
|
-
|
963
|
+
var wrapped = this._wrapped;
|
964
|
+
method.apply(wrapped, arguments);
|
965
|
+
var length = wrapped.length;
|
966
|
+
if ((name == 'shift' || name == 'splice') && length === 0) delete wrapped[0];
|
967
|
+
return result(wrapped, this._chain);
|
955
968
|
};
|
956
969
|
});
|
957
970
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: underscore-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-01-23 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|
@@ -46,9 +46,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
48
|
rubyforge_project: underscore-rails
|
49
|
-
rubygems_version: 1.8.
|
49
|
+
rubygems_version: 1.8.10
|
50
50
|
signing_key:
|
51
51
|
specification_version: 3
|
52
52
|
summary: underscore.js asset pipeline provider/wrapper
|
53
53
|
test_files: []
|
54
|
-
has_rdoc:
|