underscore-source 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Underscore
2
2
  module Source
3
- VERSION = "1.2.3"
3
+ VERSION = "1.2.4"
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
- // Underscore.js 1.2.3
2
- // (c) 2009-2011 Jeremy Ashkenas, DocumentCloud Inc.
1
+ // Underscore.js 1.2.4
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.
@@ -25,7 +25,6 @@
25
25
 
26
26
  // Create quick reference variables for speed access to core prototypes.
27
27
  var slice = ArrayProto.slice,
28
- concat = ArrayProto.concat,
29
28
  unshift = ArrayProto.unshift,
30
29
  toString = ObjProto.toString,
31
30
  hasOwnProperty = ObjProto.hasOwnProperty;
@@ -68,7 +67,7 @@
68
67
  }
69
68
 
70
69
  // Current version.
71
- _.VERSION = '1.2.3';
70
+ _.VERSION = '1.2.4';
72
71
 
73
72
  // Collection Functions
74
73
  // --------------------
@@ -102,6 +101,7 @@
102
101
  each(obj, function(value, index, list) {
103
102
  results[results.length] = iterator.call(context, value, index, list);
104
103
  });
104
+ if (obj.length === +obj.length) results.length = obj.length;
105
105
  return results;
106
106
  };
107
107
 
@@ -218,7 +218,7 @@
218
218
  _.invoke = function(obj, method) {
219
219
  var args = slice.call(arguments, 2);
220
220
  return _.map(obj, function(value) {
221
- return (method.call ? method || value : value[method]).apply(value, args);
221
+ return (_.isFunction(method) ? method || value : value[method]).apply(value, args);
222
222
  });
223
223
  };
224
224
 
@@ -583,7 +583,7 @@
583
583
  // conditionally execute the original function.
584
584
  _.wrap = function(func, wrapper) {
585
585
  return function() {
586
- var args = concat.apply([func], arguments);
586
+ var args = [func].concat(slice.call(arguments, 0));
587
587
  return wrapper.apply(this, args);
588
588
  };
589
589
  };
@@ -892,6 +892,11 @@
892
892
  escape : /<%-([\s\S]+?)%>/g
893
893
  };
894
894
 
895
+ // When customizing `templateSettings`, if you don't want to define an
896
+ // interpolation, evaluation or escaping regex, we need one that is
897
+ // guaranteed not to match.
898
+ var noMatch = /.^/;
899
+
895
900
  // JavaScript micro-templating, similar to John Resig's implementation.
896
901
  // Underscore templating handles arbitrary delimiters, preserves whitespace,
897
902
  // and correctly escapes quotes within interpolated code.
@@ -901,15 +906,16 @@
901
906
  'with(obj||{}){__p.push(\'' +
902
907
  str.replace(/\\/g, '\\\\')
903
908
  .replace(/'/g, "\\'")
904
- .replace(c.escape, function(match, code) {
909
+ .replace(c.escape || noMatch, function(match, code) {
905
910
  return "',_.escape(" + code.replace(/\\'/g, "'") + "),'";
906
911
  })
907
- .replace(c.interpolate, function(match, code) {
912
+ .replace(c.interpolate || noMatch, function(match, code) {
908
913
  return "'," + code.replace(/\\'/g, "'") + ",'";
909
914
  })
910
- .replace(c.evaluate || null, function(match, code) {
915
+ .replace(c.evaluate || noMatch, function(match, code) {
911
916
  return "');" + code.replace(/\\'/g, "'")
912
- .replace(/[\r\n\t]/g, ' ') + ";__p.push('";
917
+ .replace(/[\r\n\t]/g, ' ')
918
+ .replace(/\\\\/g, '\\') + ";__p.push('";
913
919
  })
914
920
  .replace(/\r/g, '\\r')
915
921
  .replace(/\n/g, '\\n')
@@ -922,6 +928,11 @@
922
928
  };
923
929
  };
924
930
 
931
+ // Add a "chain" function, which will delegate to the wrapper.
932
+ _.chain = function(obj) {
933
+ return _(obj).chain();
934
+ };
935
+
925
936
  // The OOP Wrapper
926
937
  // ---------------
927
938
 
@@ -954,8 +965,11 @@
954
965
  each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
955
966
  var method = ArrayProto[name];
956
967
  wrapper.prototype[name] = function() {
957
- method.apply(this._wrapped, arguments);
958
- return result(this._wrapped, this._chain);
968
+ var wrapped = this._wrapped;
969
+ method.apply(wrapped, arguments);
970
+ var length = wrapped.length;
971
+ if ((name == 'shift' || name == 'splice') && length === 0) delete wrapped[0];
972
+ return result(wrapped, this._chain);
959
973
  };
960
974
  });
961
975
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: underscore-source
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.3
5
+ version: 1.2.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel X. Moore