underscore-rails 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +21 -0
- data/Readme.md +6 -7
- data/lib/underscore-rails/version.rb +1 -1
- data/underscore-rails.gemspec +2 -1
- data/vendor/assets/javascripts/underscore.js +89 -58
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 121c2f4878563957cac04e83f26f8f007b3a3152
|
4
|
+
data.tar.gz: 0c1082f042569bf4d16f3813894bd41bce82dc88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f217295aec0b04bc1d6df709a13a4864530d778febc168b96bd9ac23658977efd0c47d7eaeea68a12aa6fdd6fc1a60c9d637d9a206cd647a91096e6a26717fb
|
7
|
+
data.tar.gz: 5ec01cbf3d18fa12addb51e516ed25f9d329518997bc9cfdbbce11d82e4128b8224cfbe4e87a779be99535343b75d54132b6d62da58e414067b4b2171c62e2e9
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Robin Wenglewski, Travis Jeffery
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Readme.md
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
Rails 3.1 asset-pipeline gem to provide underscore.js
|
2
2
|
|
3
|
-
#
|
4
|
-
|
5
|
-
gem 'underscore-rails'
|
3
|
+
# Setup
|
6
4
|
|
5
|
+
Have in your Gemfile:
|
7
6
|
|
8
|
-
|
7
|
+
gem 'underscore-rails'
|
9
8
|
|
10
|
-
|
9
|
+
And, have in your application.js manifest:
|
11
10
|
|
12
11
|
//= require underscore
|
13
12
|
|
14
|
-
|
13
|
+
(also directly available under `/assets/underscore.js`)
|
15
14
|
|
16
|
-
Easy as pie.
|
15
|
+
Easy as pie.
|
data/underscore-rails.gemspec
CHANGED
@@ -9,7 +9,8 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ["robin@wenglewski.de"]
|
10
10
|
s.homepage = "https://github.com/rweng/underscore-rails"
|
11
11
|
s.summary = %q{underscore.js asset pipeline provider/wrapper}
|
12
|
-
|
12
|
+
s.license = "MIT"
|
13
|
+
|
13
14
|
s.rubyforge_project = "underscore-rails"
|
14
15
|
|
15
16
|
s.files = `git ls-files`.split("\n")
|
@@ -1,4 +1,4 @@
|
|
1
|
-
// Underscore.js 1.5.
|
1
|
+
// Underscore.js 1.5.2
|
2
2
|
// http://underscorejs.org
|
3
3
|
// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
4
4
|
// Underscore may be freely distributed under the MIT license.
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Baseline setup
|
9
9
|
// --------------
|
10
10
|
|
11
|
-
// Establish the root object, `window` in the browser, or `
|
11
|
+
// Establish the root object, `window` in the browser, or `exports` on the server.
|
12
12
|
var root = this;
|
13
13
|
|
14
14
|
// Save the previous value of the `_` variable.
|
@@ -65,7 +65,7 @@
|
|
65
65
|
}
|
66
66
|
|
67
67
|
// Current version.
|
68
|
-
_.VERSION = '1.5.
|
68
|
+
_.VERSION = '1.5.2';
|
69
69
|
|
70
70
|
// Collection Functions
|
71
71
|
// --------------------
|
@@ -78,14 +78,13 @@
|
|
78
78
|
if (nativeForEach && obj.forEach === nativeForEach) {
|
79
79
|
obj.forEach(iterator, context);
|
80
80
|
} else if (obj.length === +obj.length) {
|
81
|
-
for (var i = 0,
|
81
|
+
for (var i = 0, length = obj.length; i < length; i++) {
|
82
82
|
if (iterator.call(context, obj[i], i, obj) === breaker) return;
|
83
83
|
}
|
84
84
|
} else {
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
}
|
85
|
+
var keys = _.keys(obj);
|
86
|
+
for (var i = 0, length = keys.length; i < length; i++) {
|
87
|
+
if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return;
|
89
88
|
}
|
90
89
|
}
|
91
90
|
};
|
@@ -284,7 +283,8 @@
|
|
284
283
|
return result.value;
|
285
284
|
};
|
286
285
|
|
287
|
-
// Shuffle an array
|
286
|
+
// Shuffle an array, using the modern version of the
|
287
|
+
// [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
|
288
288
|
_.shuffle = function(obj) {
|
289
289
|
var rand;
|
290
290
|
var index = 0;
|
@@ -297,6 +297,16 @@
|
|
297
297
|
return shuffled;
|
298
298
|
};
|
299
299
|
|
300
|
+
// Sample **n** random values from an array.
|
301
|
+
// If **n** is not specified, returns a single random element from the array.
|
302
|
+
// The internal `guard` argument allows it to work with `map`.
|
303
|
+
_.sample = function(obj, n, guard) {
|
304
|
+
if (arguments.length < 2 || guard) {
|
305
|
+
return obj[_.random(obj.length - 1)];
|
306
|
+
}
|
307
|
+
return _.shuffle(obj).slice(0, Math.max(0, n));
|
308
|
+
};
|
309
|
+
|
300
310
|
// An internal function to generate lookup iterators.
|
301
311
|
var lookupIterator = function(value) {
|
302
312
|
return _.isFunction(value) ? value : function(obj){ return obj[value]; };
|
@@ -307,9 +317,9 @@
|
|
307
317
|
var iterator = lookupIterator(value);
|
308
318
|
return _.pluck(_.map(obj, function(value, index, list) {
|
309
319
|
return {
|
310
|
-
value
|
311
|
-
index
|
312
|
-
criteria
|
320
|
+
value: value,
|
321
|
+
index: index,
|
322
|
+
criteria: iterator.call(context, value, index, list)
|
313
323
|
};
|
314
324
|
}).sort(function(left, right) {
|
315
325
|
var a = left.criteria;
|
@@ -318,38 +328,41 @@
|
|
318
328
|
if (a > b || a === void 0) return 1;
|
319
329
|
if (a < b || b === void 0) return -1;
|
320
330
|
}
|
321
|
-
return left.index
|
331
|
+
return left.index - right.index;
|
322
332
|
}), 'value');
|
323
333
|
};
|
324
334
|
|
325
335
|
// An internal function used for aggregate "group by" operations.
|
326
|
-
var group = function(
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
336
|
+
var group = function(behavior) {
|
337
|
+
return function(obj, value, context) {
|
338
|
+
var result = {};
|
339
|
+
var iterator = value == null ? _.identity : lookupIterator(value);
|
340
|
+
each(obj, function(value, index) {
|
341
|
+
var key = iterator.call(context, value, index, obj);
|
342
|
+
behavior(result, key, value);
|
343
|
+
});
|
344
|
+
return result;
|
345
|
+
};
|
334
346
|
};
|
335
347
|
|
336
348
|
// Groups the object's values by a criterion. Pass either a string attribute
|
337
349
|
// to group by, or a function that returns the criterion.
|
338
|
-
_.groupBy = function(
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
350
|
+
_.groupBy = group(function(result, key, value) {
|
351
|
+
(_.has(result, key) ? result[key] : (result[key] = [])).push(value);
|
352
|
+
});
|
353
|
+
|
354
|
+
// Indexes the object's values by a criterion, similar to `groupBy`, but for
|
355
|
+
// when you know that your index values will be unique.
|
356
|
+
_.indexBy = group(function(result, key, value) {
|
357
|
+
result[key] = value;
|
358
|
+
});
|
343
359
|
|
344
360
|
// Counts instances of an object that group by a certain criterion. Pass
|
345
361
|
// either a string attribute to count by, or a function that returns the
|
346
362
|
// criterion.
|
347
|
-
_.countBy = function(
|
348
|
-
|
349
|
-
|
350
|
-
result[key]++;
|
351
|
-
});
|
352
|
-
};
|
363
|
+
_.countBy = group(function(result, key) {
|
364
|
+
_.has(result, key) ? result[key]++ : result[key] = 1;
|
365
|
+
});
|
353
366
|
|
354
367
|
// Use a comparator function to figure out the smallest index at which
|
355
368
|
// an object should be inserted so as to maintain order. Uses binary search.
|
@@ -386,7 +399,7 @@
|
|
386
399
|
// allows it to work with `_.map`.
|
387
400
|
_.first = _.head = _.take = function(array, n, guard) {
|
388
401
|
if (array == null) return void 0;
|
389
|
-
return (n
|
402
|
+
return (n == null) || guard ? array[0] : slice.call(array, 0, n);
|
390
403
|
};
|
391
404
|
|
392
405
|
// Returns everything but the last entry of the array. Especially useful on
|
@@ -401,10 +414,10 @@
|
|
401
414
|
// values in the array. The **guard** check allows it to work with `_.map`.
|
402
415
|
_.last = function(array, n, guard) {
|
403
416
|
if (array == null) return void 0;
|
404
|
-
if ((n
|
405
|
-
return slice.call(array, Math.max(array.length - n, 0));
|
406
|
-
} else {
|
417
|
+
if ((n == null) || guard) {
|
407
418
|
return array[array.length - 1];
|
419
|
+
} else {
|
420
|
+
return slice.call(array, Math.max(array.length - n, 0));
|
408
421
|
}
|
409
422
|
};
|
410
423
|
|
@@ -436,7 +449,7 @@
|
|
436
449
|
return output;
|
437
450
|
};
|
438
451
|
|
439
|
-
//
|
452
|
+
// Flatten out an array, either recursively (by default), or just one level.
|
440
453
|
_.flatten = function(array, shallow) {
|
441
454
|
return flatten(array, shallow, []);
|
442
455
|
};
|
@@ -508,7 +521,7 @@
|
|
508
521
|
_.object = function(list, values) {
|
509
522
|
if (list == null) return {};
|
510
523
|
var result = {};
|
511
|
-
for (var i = 0,
|
524
|
+
for (var i = 0, length = list.length; i < length; i++) {
|
512
525
|
if (values) {
|
513
526
|
result[list[i]] = values[i];
|
514
527
|
} else {
|
@@ -526,17 +539,17 @@
|
|
526
539
|
// for **isSorted** to use binary search.
|
527
540
|
_.indexOf = function(array, item, isSorted) {
|
528
541
|
if (array == null) return -1;
|
529
|
-
var i = 0,
|
542
|
+
var i = 0, length = array.length;
|
530
543
|
if (isSorted) {
|
531
544
|
if (typeof isSorted == 'number') {
|
532
|
-
i = (isSorted < 0 ? Math.max(0,
|
545
|
+
i = (isSorted < 0 ? Math.max(0, length + isSorted) : isSorted);
|
533
546
|
} else {
|
534
547
|
i = _.sortedIndex(array, item);
|
535
548
|
return array[i] === item ? i : -1;
|
536
549
|
}
|
537
550
|
}
|
538
551
|
if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
|
539
|
-
for (; i <
|
552
|
+
for (; i < length; i++) if (array[i] === item) return i;
|
540
553
|
return -1;
|
541
554
|
};
|
542
555
|
|
@@ -562,11 +575,11 @@
|
|
562
575
|
}
|
563
576
|
step = arguments[2] || 1;
|
564
577
|
|
565
|
-
var
|
578
|
+
var length = Math.max(Math.ceil((stop - start) / step), 0);
|
566
579
|
var idx = 0;
|
567
|
-
var range = new Array(
|
580
|
+
var range = new Array(length);
|
568
581
|
|
569
|
-
while(idx <
|
582
|
+
while(idx < length) {
|
570
583
|
range[idx++] = start;
|
571
584
|
start += step;
|
572
585
|
}
|
@@ -678,17 +691,24 @@
|
|
678
691
|
// N milliseconds. If `immediate` is passed, trigger the function on the
|
679
692
|
// leading edge, instead of the trailing.
|
680
693
|
_.debounce = function(func, wait, immediate) {
|
681
|
-
var result;
|
682
|
-
var timeout = null;
|
694
|
+
var timeout, args, context, timestamp, result;
|
683
695
|
return function() {
|
684
|
-
|
696
|
+
context = this;
|
697
|
+
args = arguments;
|
698
|
+
timestamp = new Date();
|
685
699
|
var later = function() {
|
686
|
-
|
687
|
-
if (
|
700
|
+
var last = (new Date()) - timestamp;
|
701
|
+
if (last < wait) {
|
702
|
+
timeout = setTimeout(later, wait - last);
|
703
|
+
} else {
|
704
|
+
timeout = null;
|
705
|
+
if (!immediate) result = func.apply(context, args);
|
706
|
+
}
|
688
707
|
};
|
689
708
|
var callNow = immediate && !timeout;
|
690
|
-
|
691
|
-
|
709
|
+
if (!timeout) {
|
710
|
+
timeout = setTimeout(later, wait);
|
711
|
+
}
|
692
712
|
if (callNow) result = func.apply(context, args);
|
693
713
|
return result;
|
694
714
|
};
|
@@ -754,22 +774,33 @@
|
|
754
774
|
|
755
775
|
// Retrieve the values of an object's properties.
|
756
776
|
_.values = function(obj) {
|
757
|
-
var
|
758
|
-
|
777
|
+
var keys = _.keys(obj);
|
778
|
+
var length = keys.length;
|
779
|
+
var values = new Array(length);
|
780
|
+
for (var i = 0; i < length; i++) {
|
781
|
+
values[i] = obj[keys[i]];
|
782
|
+
}
|
759
783
|
return values;
|
760
784
|
};
|
761
785
|
|
762
786
|
// Convert an object into a list of `[key, value]` pairs.
|
763
787
|
_.pairs = function(obj) {
|
764
|
-
var
|
765
|
-
|
788
|
+
var keys = _.keys(obj);
|
789
|
+
var length = keys.length;
|
790
|
+
var pairs = new Array(length);
|
791
|
+
for (var i = 0; i < length; i++) {
|
792
|
+
pairs[i] = [keys[i], obj[keys[i]]];
|
793
|
+
}
|
766
794
|
return pairs;
|
767
795
|
};
|
768
796
|
|
769
797
|
// Invert the keys and values of an object. The values must be serializable.
|
770
798
|
_.invert = function(obj) {
|
771
799
|
var result = {};
|
772
|
-
|
800
|
+
var keys = _.keys(obj);
|
801
|
+
for (var i = 0, length = keys.length; i < length; i++) {
|
802
|
+
result[obj[keys[i]]] = keys[i];
|
803
|
+
}
|
773
804
|
return result;
|
774
805
|
};
|
775
806
|
|
@@ -1084,7 +1115,7 @@
|
|
1084
1115
|
|
1085
1116
|
// Add your own custom functions to the Underscore object.
|
1086
1117
|
_.mixin = function(obj) {
|
1087
|
-
each(_.functions(obj), function(name){
|
1118
|
+
each(_.functions(obj), function(name) {
|
1088
1119
|
var func = _[name] = obj[name];
|
1089
1120
|
_.prototype[name] = function() {
|
1090
1121
|
var args = [this._wrapped];
|
@@ -1242,4 +1273,4 @@
|
|
1242
1273
|
|
1243
1274
|
});
|
1244
1275
|
|
1245
|
-
}).call(this);
|
1276
|
+
}).call(this);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: underscore-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robin Wenglewski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -19,6 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- .gitignore
|
21
21
|
- Gemfile
|
22
|
+
- LICENSE.md
|
22
23
|
- Rakefile
|
23
24
|
- Readme.md
|
24
25
|
- lib/underscore-rails.rb
|
@@ -26,7 +27,8 @@ files:
|
|
26
27
|
- underscore-rails.gemspec
|
27
28
|
- vendor/assets/javascripts/underscore.js
|
28
29
|
homepage: https://github.com/rweng/underscore-rails
|
29
|
-
licenses:
|
30
|
+
licenses:
|
31
|
+
- MIT
|
30
32
|
metadata: {}
|
31
33
|
post_install_message:
|
32
34
|
rdoc_options: []
|