backbone-rails 0.5.3 → 0.5.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/vendor/assets/javascripts/underscore.js +236 -98
- metadata +4 -4
@@ -1,4 +1,4 @@
|
|
1
|
-
// Underscore.js 1.
|
1
|
+
// Underscore.js 1.2.2
|
2
2
|
// (c) 2011 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,
|
@@ -48,19 +48,26 @@
|
|
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 **CommonJS**, with
|
52
|
-
// for the old `require()` API. If we're not in
|
53
|
-
// global object.
|
54
|
-
if (typeof
|
55
|
-
module.exports
|
56
|
-
|
51
|
+
// Export the Underscore object for **Node.js** and **"CommonJS"**, with
|
52
|
+
// backwards-compatibility for the old `require()` API. If we're not in
|
53
|
+
// CommonJS, add `_` to the global object.
|
54
|
+
if (typeof exports !== 'undefined') {
|
55
|
+
if (typeof module !== 'undefined' && module.exports) {
|
56
|
+
exports = module.exports = _;
|
57
|
+
}
|
58
|
+
exports._ = _;
|
59
|
+
} else if (typeof define === 'function' && define.amd) {
|
60
|
+
// Register as a named module with AMD.
|
61
|
+
define('underscore', function() {
|
62
|
+
return _;
|
63
|
+
});
|
57
64
|
} else {
|
58
65
|
// Exported as a string, for Closure Compiler "advanced" mode.
|
59
66
|
root['_'] = _;
|
60
67
|
}
|
61
68
|
|
62
69
|
// Current version.
|
63
|
-
_.VERSION = '1.
|
70
|
+
_.VERSION = '1.2.2';
|
64
71
|
|
65
72
|
// Collection Functions
|
66
73
|
// --------------------
|
@@ -187,7 +194,7 @@
|
|
187
194
|
if (obj == null) return result;
|
188
195
|
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
|
189
196
|
each(obj, function(value, index, list) {
|
190
|
-
if (result
|
197
|
+
if (result || (result = iterator.call(context, value, index, list))) return breaker;
|
191
198
|
});
|
192
199
|
return !!result;
|
193
200
|
};
|
@@ -198,8 +205,8 @@
|
|
198
205
|
var found = false;
|
199
206
|
if (obj == null) return found;
|
200
207
|
if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
|
201
|
-
any(obj, function(value) {
|
202
|
-
|
208
|
+
found = any(obj, function(value) {
|
209
|
+
return value === target;
|
203
210
|
});
|
204
211
|
return found;
|
205
212
|
};
|
@@ -220,6 +227,7 @@
|
|
220
227
|
// Return the maximum element or (element-based computation).
|
221
228
|
_.max = function(obj, iterator, context) {
|
222
229
|
if (!iterator && _.isArray(obj)) return Math.max.apply(Math, obj);
|
230
|
+
if (!iterator && _.isEmpty(obj)) return -Infinity;
|
223
231
|
var result = {computed : -Infinity};
|
224
232
|
each(obj, function(value, index, list) {
|
225
233
|
var computed = iterator ? iterator.call(context, value, index, list) : value;
|
@@ -231,6 +239,7 @@
|
|
231
239
|
// Return the minimum element (or element-based computation).
|
232
240
|
_.min = function(obj, iterator, context) {
|
233
241
|
if (!iterator && _.isArray(obj)) return Math.min.apply(Math, obj);
|
242
|
+
if (!iterator && _.isEmpty(obj)) return Infinity;
|
234
243
|
var result = {computed : Infinity};
|
235
244
|
each(obj, function(value, index, list) {
|
236
245
|
var computed = iterator ? iterator.call(context, value, index, list) : value;
|
@@ -239,6 +248,21 @@
|
|
239
248
|
return result.value;
|
240
249
|
};
|
241
250
|
|
251
|
+
// Shuffle an array.
|
252
|
+
_.shuffle = function(obj) {
|
253
|
+
var shuffled = [], rand;
|
254
|
+
each(obj, function(value, index, list) {
|
255
|
+
if (index == 0) {
|
256
|
+
shuffled[0] = value;
|
257
|
+
} else {
|
258
|
+
rand = Math.floor(Math.random() * (index + 1));
|
259
|
+
shuffled[index] = shuffled[rand];
|
260
|
+
shuffled[rand] = value;
|
261
|
+
}
|
262
|
+
});
|
263
|
+
return shuffled;
|
264
|
+
};
|
265
|
+
|
242
266
|
// Sort the object's values by a criterion produced by an iterator.
|
243
267
|
_.sortBy = function(obj, iterator, context) {
|
244
268
|
return _.pluck(_.map(obj, function(value, index, list) {
|
@@ -252,9 +276,11 @@
|
|
252
276
|
}), 'value');
|
253
277
|
};
|
254
278
|
|
255
|
-
// Groups the object's values by a criterion
|
256
|
-
|
279
|
+
// Groups the object's values by a criterion. Pass either a string attribute
|
280
|
+
// to group by, or a function that returns the criterion.
|
281
|
+
_.groupBy = function(obj, val) {
|
257
282
|
var result = {};
|
283
|
+
var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; };
|
258
284
|
each(obj, function(value, index) {
|
259
285
|
var key = iterator(value, index);
|
260
286
|
(result[key] || (result[key] = [])).push(value);
|
@@ -298,6 +324,24 @@
|
|
298
324
|
return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
|
299
325
|
};
|
300
326
|
|
327
|
+
// Returns everything but the last entry of the array. Especcialy useful on
|
328
|
+
// the arguments object. Passing **n** will return all the values in
|
329
|
+
// the array, excluding the last N. The **guard** check allows it to work with
|
330
|
+
// `_.map`.
|
331
|
+
_.initial = function(array, n, guard) {
|
332
|
+
return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
|
333
|
+
};
|
334
|
+
|
335
|
+
// Get the last element of an array. Passing **n** will return the last N
|
336
|
+
// values in the array. The **guard** check allows it to work with `_.map`.
|
337
|
+
_.last = function(array, n, guard) {
|
338
|
+
if ((n != null) && !guard) {
|
339
|
+
return slice.call(array, Math.max(array.length - n, 0));
|
340
|
+
} else {
|
341
|
+
return array[array.length - 1];
|
342
|
+
}
|
343
|
+
};
|
344
|
+
|
301
345
|
// Returns everything but the first entry of the array. Aliased as `tail`.
|
302
346
|
// Especially useful on the arguments object. Passing an **index** will return
|
303
347
|
// the rest of the values in the array from that index onward. The **guard**
|
@@ -306,20 +350,15 @@
|
|
306
350
|
return slice.call(array, (index == null) || guard ? 1 : index);
|
307
351
|
};
|
308
352
|
|
309
|
-
// Get the last element of an array.
|
310
|
-
_.last = function(array) {
|
311
|
-
return array[array.length - 1];
|
312
|
-
};
|
313
|
-
|
314
353
|
// Trim out all falsy values from an array.
|
315
354
|
_.compact = function(array) {
|
316
355
|
return _.filter(array, function(value){ return !!value; });
|
317
356
|
};
|
318
357
|
|
319
358
|
// Return a completely flattened version of an array.
|
320
|
-
_.flatten = function(array) {
|
359
|
+
_.flatten = function(array, shallow) {
|
321
360
|
return _.reduce(array, function(memo, value) {
|
322
|
-
if (_.isArray(value)) return memo.concat(_.flatten(value));
|
361
|
+
if (_.isArray(value)) return memo.concat(shallow ? value : _.flatten(value));
|
323
362
|
memo[memo.length] = value;
|
324
363
|
return memo;
|
325
364
|
}, []);
|
@@ -333,17 +372,23 @@
|
|
333
372
|
// Produce a duplicate-free version of the array. If the array has already
|
334
373
|
// been sorted, you have the option of using a faster algorithm.
|
335
374
|
// Aliased as `unique`.
|
336
|
-
_.uniq = _.unique = function(array, isSorted) {
|
337
|
-
|
338
|
-
|
375
|
+
_.uniq = _.unique = function(array, isSorted, iterator) {
|
376
|
+
var initial = iterator ? _.map(array, iterator) : array;
|
377
|
+
var result = [];
|
378
|
+
_.reduce(initial, function(memo, el, i) {
|
379
|
+
if (0 == i || (isSorted === true ? _.last(memo) != el : !_.include(memo, el))) {
|
380
|
+
memo[memo.length] = el;
|
381
|
+
result[result.length] = array[i];
|
382
|
+
}
|
339
383
|
return memo;
|
340
384
|
}, []);
|
385
|
+
return result;
|
341
386
|
};
|
342
387
|
|
343
388
|
// Produce an array that contains the union: each distinct element from all of
|
344
389
|
// the passed-in arrays.
|
345
390
|
_.union = function() {
|
346
|
-
return _.uniq(_.flatten(arguments));
|
391
|
+
return _.uniq(_.flatten(arguments, true));
|
347
392
|
};
|
348
393
|
|
349
394
|
// Produce an array that contains every item shared between all the
|
@@ -391,7 +436,6 @@
|
|
391
436
|
return -1;
|
392
437
|
};
|
393
438
|
|
394
|
-
|
395
439
|
// Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
|
396
440
|
_.lastIndexOf = function(array, item) {
|
397
441
|
if (array == null) return -1;
|
@@ -426,15 +470,25 @@
|
|
426
470
|
// Function (ahem) Functions
|
427
471
|
// ------------------
|
428
472
|
|
473
|
+
// Reusable constructor function for prototype setting.
|
474
|
+
var ctor = function(){};
|
475
|
+
|
429
476
|
// Create a function bound to a given object (assigning `this`, and arguments,
|
430
477
|
// optionally). Binding with arguments is also known as `curry`.
|
431
478
|
// Delegates to **ECMAScript 5**'s native `Function.bind` if available.
|
432
479
|
// We check for `func.bind` first, to fail fast when `func` is undefined.
|
433
|
-
_.bind = function(func,
|
480
|
+
_.bind = function bind(func, context) {
|
481
|
+
var bound, args;
|
434
482
|
if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
|
435
|
-
|
436
|
-
|
437
|
-
|
483
|
+
if (!_.isFunction(func)) throw new TypeError;
|
484
|
+
args = slice.call(arguments, 2);
|
485
|
+
return bound = function() {
|
486
|
+
if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
|
487
|
+
ctor.prototype = func.prototype;
|
488
|
+
var self = new ctor;
|
489
|
+
var result = func.apply(self, args.concat(slice.call(arguments)));
|
490
|
+
if (Object(result) === result) return result;
|
491
|
+
return self;
|
438
492
|
};
|
439
493
|
};
|
440
494
|
|
@@ -470,31 +524,43 @@
|
|
470
524
|
return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
|
471
525
|
};
|
472
526
|
|
473
|
-
//
|
474
|
-
|
475
|
-
|
527
|
+
// Returns a function, that, when invoked, will only be triggered at most once
|
528
|
+
// during a given window of time.
|
529
|
+
_.throttle = function(func, wait) {
|
530
|
+
var context, args, timeout, throttling, more;
|
531
|
+
var whenDone = _.debounce(function(){ more = throttling = false; }, wait);
|
476
532
|
return function() {
|
477
|
-
|
478
|
-
var
|
533
|
+
context = this; args = arguments;
|
534
|
+
var later = function() {
|
479
535
|
timeout = null;
|
480
|
-
func.apply(context, args);
|
536
|
+
if (more) func.apply(context, args);
|
537
|
+
whenDone();
|
481
538
|
};
|
482
|
-
if (
|
483
|
-
if (
|
539
|
+
if (!timeout) timeout = setTimeout(later, wait);
|
540
|
+
if (throttling) {
|
541
|
+
more = true;
|
542
|
+
} else {
|
543
|
+
func.apply(context, args);
|
544
|
+
}
|
545
|
+
whenDone();
|
546
|
+
throttling = true;
|
484
547
|
};
|
485
548
|
};
|
486
549
|
|
487
|
-
// Returns a function, that, when invoked, will only be triggered at most once
|
488
|
-
// during a given window of time.
|
489
|
-
_.throttle = function(func, wait) {
|
490
|
-
return limit(func, wait, false);
|
491
|
-
};
|
492
|
-
|
493
550
|
// Returns a function, that, as long as it continues to be invoked, will not
|
494
551
|
// be triggered. The function will be called after it stops being called for
|
495
552
|
// N milliseconds.
|
496
553
|
_.debounce = function(func, wait) {
|
497
|
-
|
554
|
+
var timeout;
|
555
|
+
return function() {
|
556
|
+
var context = this, args = arguments;
|
557
|
+
var later = function() {
|
558
|
+
timeout = null;
|
559
|
+
func.apply(context, args);
|
560
|
+
};
|
561
|
+
clearTimeout(timeout);
|
562
|
+
timeout = setTimeout(later, wait);
|
563
|
+
};
|
498
564
|
};
|
499
565
|
|
500
566
|
// Returns a function that will be executed at most one time, no matter how
|
@@ -533,12 +599,12 @@
|
|
533
599
|
|
534
600
|
// Returns a function that will only be executed after being called N times.
|
535
601
|
_.after = function(times, func) {
|
602
|
+
if (times <= 0) return func();
|
536
603
|
return function() {
|
537
604
|
if (--times < 1) { return func.apply(this, arguments); }
|
538
605
|
};
|
539
606
|
};
|
540
607
|
|
541
|
-
|
542
608
|
// Object Functions
|
543
609
|
// ----------------
|
544
610
|
|
@@ -588,6 +654,7 @@
|
|
588
654
|
|
589
655
|
// Create a (shallow-cloned) duplicate of an object.
|
590
656
|
_.clone = function(obj) {
|
657
|
+
if (!_.isObject(obj)) return obj;
|
591
658
|
return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
|
592
659
|
};
|
593
660
|
|
@@ -599,47 +666,103 @@
|
|
599
666
|
return obj;
|
600
667
|
};
|
601
668
|
|
602
|
-
//
|
603
|
-
|
604
|
-
//
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
if (
|
609
|
-
// Basic equality test (watch out for coercions).
|
610
|
-
if (a == b) return true;
|
611
|
-
// One is falsy and the other truthy.
|
612
|
-
if ((!a && b) || (a && !b)) return false;
|
669
|
+
// Internal recursive comparison function.
|
670
|
+
function eq(a, b, stack) {
|
671
|
+
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
672
|
+
// See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal.
|
673
|
+
if (a === b) return a !== 0 || 1 / a == 1 / b;
|
674
|
+
// A strict comparison is necessary because `null == undefined`.
|
675
|
+
if (a == null || b == null) return a === b;
|
613
676
|
// Unwrap any wrapped objects.
|
614
677
|
if (a._chain) a = a._wrapped;
|
615
678
|
if (b._chain) b = b._wrapped;
|
616
|
-
//
|
617
|
-
if (a.isEqual) return a.isEqual(b);
|
618
|
-
if (b.isEqual) return b.isEqual(a);
|
619
|
-
//
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
679
|
+
// 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);
|
682
|
+
// Compare `[[Class]]` names.
|
683
|
+
var className = toString.call(a);
|
684
|
+
if (className != toString.call(b)) return false;
|
685
|
+
switch (className) {
|
686
|
+
// Strings, numbers, dates, and booleans are compared by value.
|
687
|
+
case '[object String]':
|
688
|
+
// Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
|
689
|
+
// equivalent to `new String("5")`.
|
690
|
+
return String(a) == String(b);
|
691
|
+
case '[object Number]':
|
692
|
+
a = +a;
|
693
|
+
b = +b;
|
694
|
+
// `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
|
695
|
+
// other numeric values.
|
696
|
+
return a != a ? b != b : (a == 0 ? 1 / a == 1 / b : a == b);
|
697
|
+
case '[object Date]':
|
698
|
+
case '[object Boolean]':
|
699
|
+
// Coerce dates and booleans to numeric primitive values. Dates are compared by their
|
700
|
+
// millisecond representations. Note that invalid dates with millisecond representations
|
701
|
+
// of `NaN` are not equivalent.
|
702
|
+
return +a == +b;
|
703
|
+
// RegExps are compared by their source patterns and flags.
|
704
|
+
case '[object RegExp]':
|
705
|
+
return a.source == b.source &&
|
706
|
+
a.global == b.global &&
|
707
|
+
a.multiline == b.multiline &&
|
708
|
+
a.ignoreCase == b.ignoreCase;
|
709
|
+
}
|
710
|
+
if (typeof a != 'object' || typeof b != 'object') return false;
|
711
|
+
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
712
|
+
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
713
|
+
var length = stack.length;
|
714
|
+
while (length--) {
|
715
|
+
// Linear search. Performance is inversely proportional to the number of
|
716
|
+
// unique nested structures.
|
717
|
+
if (stack[length] == a) return true;
|
718
|
+
}
|
719
|
+
// Add the first object to the stack of traversed objects.
|
720
|
+
stack.push(a);
|
721
|
+
var size = 0, result = true;
|
722
|
+
// Recursively compare objects and arrays.
|
723
|
+
if (className == '[object Array]') {
|
724
|
+
// Compare array lengths to determine if a deep comparison is necessary.
|
725
|
+
size = a.length;
|
726
|
+
result = size == b.length;
|
727
|
+
if (result) {
|
728
|
+
// Deep compare the contents, ignoring non-numeric properties.
|
729
|
+
while (size--) {
|
730
|
+
// Ensure commutative equality for sparse arrays.
|
731
|
+
if (!(result = size in a == size in b && eq(a[size], b[size], stack))) break;
|
732
|
+
}
|
733
|
+
}
|
734
|
+
} else {
|
735
|
+
// Objects with different constructors are not equivalent.
|
736
|
+
if ("constructor" in a != "constructor" in b || a.constructor != b.constructor) return false;
|
737
|
+
// Deep compare objects.
|
738
|
+
for (var key in a) {
|
739
|
+
if (hasOwnProperty.call(a, key)) {
|
740
|
+
// Count the expected number of properties.
|
741
|
+
size++;
|
742
|
+
// Deep compare each member.
|
743
|
+
if (!(result = hasOwnProperty.call(b, key) && eq(a[key], b[key], stack))) break;
|
744
|
+
}
|
745
|
+
}
|
746
|
+
// Ensure that both objects contain the same number of properties.
|
747
|
+
if (result) {
|
748
|
+
for (key in b) {
|
749
|
+
if (hasOwnProperty.call(b, key) && !(size--)) break;
|
750
|
+
}
|
751
|
+
result = !size;
|
752
|
+
}
|
753
|
+
}
|
754
|
+
// Remove the first object from the stack of traversed objects.
|
755
|
+
stack.pop();
|
756
|
+
return result;
|
757
|
+
}
|
758
|
+
|
759
|
+
// Perform a deep comparison to check if two objects are equal.
|
760
|
+
_.isEqual = function(a, b) {
|
761
|
+
return eq(a, b, []);
|
640
762
|
};
|
641
763
|
|
642
|
-
// Is a given array or object empty?
|
764
|
+
// Is a given array, string, or object empty?
|
765
|
+
// An "empty" object has no enumerable own-properties.
|
643
766
|
_.isEmpty = function(obj) {
|
644
767
|
if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
|
645
768
|
for (var key in obj) if (hasOwnProperty.call(obj, key)) return false;
|
@@ -654,7 +777,7 @@
|
|
654
777
|
// Is a given value an array?
|
655
778
|
// Delegates to ECMA5's native Array.isArray
|
656
779
|
_.isArray = nativeIsArray || function(obj) {
|
657
|
-
return toString.call(obj)
|
780
|
+
return toString.call(obj) == '[object Array]';
|
658
781
|
};
|
659
782
|
|
660
783
|
// Is a given variable an object?
|
@@ -663,44 +786,50 @@
|
|
663
786
|
};
|
664
787
|
|
665
788
|
// Is a given variable an arguments object?
|
666
|
-
|
667
|
-
|
668
|
-
|
789
|
+
if (toString.call(arguments) == '[object Arguments]') {
|
790
|
+
_.isArguments = function(obj) {
|
791
|
+
return toString.call(obj) == '[object Arguments]';
|
792
|
+
};
|
793
|
+
} else {
|
794
|
+
_.isArguments = function(obj) {
|
795
|
+
return !!(obj && hasOwnProperty.call(obj, 'callee'));
|
796
|
+
};
|
797
|
+
}
|
669
798
|
|
670
799
|
// Is a given value a function?
|
671
800
|
_.isFunction = function(obj) {
|
672
|
-
return
|
801
|
+
return toString.call(obj) == '[object Function]';
|
673
802
|
};
|
674
803
|
|
675
804
|
// Is a given value a string?
|
676
805
|
_.isString = function(obj) {
|
677
|
-
return
|
806
|
+
return toString.call(obj) == '[object String]';
|
678
807
|
};
|
679
808
|
|
680
809
|
// Is a given value a number?
|
681
810
|
_.isNumber = function(obj) {
|
682
|
-
return
|
811
|
+
return toString.call(obj) == '[object Number]';
|
683
812
|
};
|
684
813
|
|
685
|
-
// Is the given value `NaN`?
|
686
|
-
// that does not equal itself.
|
814
|
+
// Is the given value `NaN`?
|
687
815
|
_.isNaN = function(obj) {
|
816
|
+
// `NaN` is the only value for which `===` is not reflexive.
|
688
817
|
return obj !== obj;
|
689
818
|
};
|
690
819
|
|
691
820
|
// Is a given value a boolean?
|
692
821
|
_.isBoolean = function(obj) {
|
693
|
-
return obj === true || obj === false;
|
822
|
+
return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
|
694
823
|
};
|
695
824
|
|
696
825
|
// Is a given value a date?
|
697
826
|
_.isDate = function(obj) {
|
698
|
-
return
|
827
|
+
return toString.call(obj) == '[object Date]';
|
699
828
|
};
|
700
829
|
|
701
830
|
// Is the given value a regular expression?
|
702
831
|
_.isRegExp = function(obj) {
|
703
|
-
return
|
832
|
+
return toString.call(obj) == '[object RegExp]';
|
704
833
|
};
|
705
834
|
|
706
835
|
// Is a given value equal to null?
|
@@ -733,6 +862,11 @@
|
|
733
862
|
for (var i = 0; i < n; i++) iterator.call(context, i);
|
734
863
|
};
|
735
864
|
|
865
|
+
// Escape a string for HTML interpolation.
|
866
|
+
_.escape = function(string) {
|
867
|
+
return (''+string).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/');
|
868
|
+
};
|
869
|
+
|
736
870
|
// Add your own custom functions to the Underscore object, ensuring that
|
737
871
|
// they're correctly added to the OOP wrapper as well.
|
738
872
|
_.mixin = function(obj) {
|
@@ -753,7 +887,8 @@
|
|
753
887
|
// following template settings to use alternative delimiters.
|
754
888
|
_.templateSettings = {
|
755
889
|
evaluate : /<%([\s\S]+?)%>/g,
|
756
|
-
interpolate : /<%=([\s\S]+?)%>/g
|
890
|
+
interpolate : /<%=([\s\S]+?)%>/g,
|
891
|
+
escape : /<%-([\s\S]+?)%>/g
|
757
892
|
};
|
758
893
|
|
759
894
|
// JavaScript micro-templating, similar to John Resig's implementation.
|
@@ -765,19 +900,22 @@
|
|
765
900
|
'with(obj||{}){__p.push(\'' +
|
766
901
|
str.replace(/\\/g, '\\\\')
|
767
902
|
.replace(/'/g, "\\'")
|
903
|
+
.replace(c.escape, function(match, code) {
|
904
|
+
return "',_.escape(" + code.replace(/\\'/g, "'") + "),'";
|
905
|
+
})
|
768
906
|
.replace(c.interpolate, function(match, code) {
|
769
907
|
return "'," + code.replace(/\\'/g, "'") + ",'";
|
770
908
|
})
|
771
909
|
.replace(c.evaluate || null, function(match, code) {
|
772
910
|
return "');" + code.replace(/\\'/g, "'")
|
773
|
-
.replace(/[\r\n\t]/g, ' ') + "__p.push('";
|
911
|
+
.replace(/[\r\n\t]/g, ' ') + ";__p.push('";
|
774
912
|
})
|
775
913
|
.replace(/\r/g, '\\r')
|
776
914
|
.replace(/\n/g, '\\n')
|
777
915
|
.replace(/\t/g, '\\t')
|
778
916
|
+ "');}return __p.join('');";
|
779
|
-
var func = new Function('obj', tmpl);
|
780
|
-
return data ? func(data) : func;
|
917
|
+
var func = new Function('obj', '_', tmpl);
|
918
|
+
return data ? func(data, _) : function(data) { return func(data, _) };
|
781
919
|
};
|
782
920
|
|
783
921
|
// The OOP Wrapper
|
@@ -836,4 +974,4 @@
|
|
836
974
|
return this._wrapped;
|
837
975
|
};
|
838
976
|
|
839
|
-
})();
|
977
|
+
}).call(this);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backbone-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.3
|
4
|
+
version: 0.5.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-22 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153699680 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153699680
|
25
25
|
description: Ships backbone and underscore to your Rails 3.1 application through the
|
26
26
|
new asset pipeline. Rails 3.0 is supported via generators.
|
27
27
|
email:
|