underscore-rails 1.4.3 → 1.4.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 Rails
3
- VERSION = "1.4.3"
3
+ VERSION = "1.4.4"
4
4
  end
5
5
  end
@@ -2,10 +2,10 @@ require "underscore-rails/version"
2
2
 
3
3
  module Underscore
4
4
  module Rails
5
- if defined?(::Rails) and ::Rails.version >= "3.1"
6
- class Rails::Engine < ::Rails::Engine
7
- # this class enables the asset pipeline
8
- end
9
- end
5
+ if defined?(::Rails) and Gem::Requirement.new('>= 3.1').satisfied_by?(Gem::Version.new ::Rails.version)
6
+ class Rails::Engine < ::Rails::Engine
7
+ # this class enables the asset pipeline
8
+ end
9
+ end
10
10
  end
11
11
  end
@@ -1,6 +1,6 @@
1
- // Underscore.js 1.4.3
1
+ // Underscore.js 1.4.4
2
2
  // http://underscorejs.org
3
- // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
3
+ // (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
4
4
  // Underscore may be freely distributed under the MIT license.
5
5
 
6
6
  (function() {
@@ -64,7 +64,7 @@
64
64
  }
65
65
 
66
66
  // Current version.
67
- _.VERSION = '1.4.3';
67
+ _.VERSION = '1.4.4';
68
68
 
69
69
  // Collection Functions
70
70
  // --------------------
@@ -224,8 +224,9 @@
224
224
  // Invoke a method (with arguments) on every item in a collection.
225
225
  _.invoke = function(obj, method) {
226
226
  var args = slice.call(arguments, 2);
227
+ var isFunc = _.isFunction(method);
227
228
  return _.map(obj, function(value) {
228
- return (_.isFunction(method) ? method : value[method]).apply(value, args);
229
+ return (isFunc ? method : value[method]).apply(value, args);
229
230
  });
230
231
  };
231
232
 
@@ -235,10 +236,10 @@
235
236
  };
236
237
 
237
238
  // Convenience version of a common use case of `filter`: selecting only objects
238
- // with specific `key:value` pairs.
239
- _.where = function(obj, attrs) {
240
- if (_.isEmpty(attrs)) return [];
241
- return _.filter(obj, function(value) {
239
+ // containing specific `key:value` pairs.
240
+ _.where = function(obj, attrs, first) {
241
+ if (_.isEmpty(attrs)) return first ? void 0 : [];
242
+ return _[first ? 'find' : 'filter'](obj, function(value) {
242
243
  for (var key in attrs) {
243
244
  if (attrs[key] !== value[key]) return false;
244
245
  }
@@ -246,6 +247,12 @@
246
247
  });
247
248
  };
248
249
 
250
+ // Convenience version of a common use case of `find`: getting the first object
251
+ // containing specific `key:value` pairs.
252
+ _.findWhere = function(obj, attrs) {
253
+ return _.where(obj, attrs, true);
254
+ };
255
+
249
256
  // Return the maximum element or (element-based computation).
250
257
  // Can't optimize arrays of integers longer than 65,535 elements.
251
258
  // See: https://bugs.webkit.org/show_bug.cgi?id=80797
@@ -317,7 +324,7 @@
317
324
  // An internal function used for aggregate "group by" operations.
318
325
  var group = function(obj, value, context, behavior) {
319
326
  var result = {};
320
- var iterator = lookupIterator(value || _.identity);
327
+ var iterator = lookupIterator(value == null ? _.identity : value);
321
328
  each(obj, function(value, index) {
322
329
  var key = iterator.call(context, value, index, obj);
323
330
  behavior(result, key, value);
@@ -571,9 +578,8 @@
571
578
  var ctor = function(){};
572
579
 
573
580
  // Create a function bound to a given object (assigning `this`, and arguments,
574
- // optionally). Binding with arguments is also known as `curry`.
575
- // Delegates to **ECMAScript 5**'s native `Function.bind` if available.
576
- // We check for `func.bind` first, to fail fast when `func` is undefined.
581
+ // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
582
+ // available.
577
583
  _.bind = function(func, context) {
578
584
  var args, bound;
579
585
  if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
@@ -590,11 +596,20 @@
590
596
  };
591
597
  };
592
598
 
599
+ // Partially apply a function by creating a version that has had some of its
600
+ // arguments pre-filled, without changing its dynamic `this` context.
601
+ _.partial = function(func) {
602
+ var args = slice.call(arguments, 1);
603
+ return function() {
604
+ return func.apply(this, args.concat(slice.call(arguments)));
605
+ };
606
+ };
607
+
593
608
  // Bind all of an object's methods to that object. Useful for ensuring that
594
609
  // all callbacks defined on an object belong to it.
595
610
  _.bindAll = function(obj) {
596
611
  var funcs = slice.call(arguments, 1);
597
- if (funcs.length == 0) funcs = _.functions(obj);
612
+ if (funcs.length === 0) throw new Error("bindAll must be passed function names");
598
613
  each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
599
614
  return obj;
600
615
  };
@@ -796,7 +811,7 @@
796
811
  each(slice.call(arguments, 1), function(source) {
797
812
  if (source) {
798
813
  for (var prop in source) {
799
- if (obj[prop] == null) obj[prop] = source[prop];
814
+ if (obj[prop] === void 0) obj[prop] = source[prop];
800
815
  }
801
816
  }
802
817
  });
@@ -1019,7 +1034,7 @@
1019
1034
  max = min;
1020
1035
  min = 0;
1021
1036
  }
1022
- return min + (0 | Math.random() * (max - min + 1));
1037
+ return min + Math.floor(Math.random() * (max - min + 1));
1023
1038
  };
1024
1039
 
1025
1040
  // List of HTML entities for escaping.
@@ -1054,7 +1069,7 @@
1054
1069
  // If the value of the named property is a function then invoke it;
1055
1070
  // otherwise, return it.
1056
1071
  _.result = function(object, property) {
1057
- if (object == null) return null;
1072
+ if (object == null) return void 0;
1058
1073
  var value = object[property];
1059
1074
  return _.isFunction(value) ? value.call(object) : value;
1060
1075
  };
@@ -1075,7 +1090,7 @@
1075
1090
  // Useful for temporary DOM ids.
1076
1091
  var idCounter = 0;
1077
1092
  _.uniqueId = function(prefix) {
1078
- var id = '' + ++idCounter;
1093
+ var id = ++idCounter + '';
1079
1094
  return prefix ? prefix + id : id;
1080
1095
  };
1081
1096
 
@@ -1110,6 +1125,7 @@
1110
1125
  // Underscore templating handles arbitrary delimiters, preserves whitespace,
1111
1126
  // and correctly escapes quotes within interpolated code.
1112
1127
  _.template = function(text, data, settings) {
1128
+ var render;
1113
1129
  settings = _.defaults({}, settings, _.templateSettings);
1114
1130
 
1115
1131
  // Combine delimiters into one regular expression via alternation.
@@ -1148,7 +1164,7 @@
1148
1164
  source + "return __p;\n";
1149
1165
 
1150
1166
  try {
1151
- var render = new Function(settings.variable || 'obj', '_', source);
1167
+ render = new Function(settings.variable || 'obj', '_', source);
1152
1168
  } catch (e) {
1153
1169
  e.source = source;
1154
1170
  throw e;
@@ -1218,4 +1234,4 @@
1218
1234
 
1219
1235
  });
1220
1236
 
1221
- }).call(this);
1237
+ }).call(this);
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.3
4
+ version: 1.4.4
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: 2012-12-10 00:00:00.000000000 Z
12
+ date: 2013-04-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: