backbone_extensions 0.0.23 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env rake
2
+ ENV['JASMINE_SPEC_FORMAT'] = 'Fuubar'
2
3
  begin
3
4
  require 'bundler/setup'
4
5
  rescue LoadError
5
6
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
7
  end
7
8
 
9
+ require 'yajl/json_gem'
8
10
  Bundler::GemHelper.install_tasks
9
11
 
10
12
  require 'jshint/tasks'
@@ -1,21 +1,22 @@
1
1
  //= require backbone_extensions/include
2
2
  //= require underscore.string
3
- (function(_, Backbone) {
3
+ (function() {
4
4
  'use strict';
5
- var global = this, fn = {};
5
+ var exports = this, _ = exports._, Backbone = exports.Backbone;
6
+ var fn = {};
6
7
  function mixin(namespace, globalOptions) {
7
- namespace = namespace || global || {};
8
+ namespace = namespace || exports || {};
8
9
  globalOptions = globalOptions || {};
9
- _(fn).extend({
10
+ _.extend(fn, {
10
11
  mergeOptions: function() {
11
- return _(arguments).chain().toArray().reduce(function(result, options) { return _(result).extend(options); }, {})
12
+ return _.chain(arguments).toArray().reduce(function(result, options) { return _.extend(result, options); }, {})
12
13
  .omit('class', 'className', 'inverseOf', 'parseName', 'through').value();
13
14
  },
14
15
 
15
16
  buildAssociation: function(namespace, associationType, associationName, options) {
16
17
  function through() {
17
18
  function association() {
18
- var t = (_(options.through).isFunction() && options.through.call(this)) || _.str.camelize(options.through);
19
+ var t = (_.isFunction(options.through) && options.through.call(this)) || _.str.camelize(options.through);
19
20
  return this[t] && this[t]() && this[t]()[associationName] && this[t]()[associationName]();
20
21
  }
21
22
  return options.through && association.call(this);
@@ -34,9 +35,9 @@
34
35
  newOptions[_.str.camelize(options.inverseOf)] = function() { return self; };
35
36
  }
36
37
 
37
- return _((options['class'] && new options['class'](null, newOptions)) ||
38
+ return _.tap((options['class'] && new options['class'](null, newOptions)) ||
38
39
  (className && namespace[className] && new namespace[className](null, newOptions)) ||
39
- (namespace[collectionName] && new namespace[collectionName](null, newOptions))).tap(function(association) {
40
+ (namespace[collectionName] && new namespace[collectionName](null, newOptions)), function(association) {
40
41
  through.call(self, association);
41
42
  });
42
43
  }
@@ -49,28 +50,28 @@
49
50
 
50
51
  this.prototype[associationName] = function() {
51
52
  return (this._associations || (this._associations = {})) && this._associations[associationName] ||
52
- (this._associations[associationName] = (this._options && _(this._options).result(associationName)) || associations[associationType].call(this));
53
+ (this._associations[associationName] = (this._options && _.result(this._options, associationName)) || associations[associationType].call(this));
53
54
  };
54
55
  },
55
56
 
56
57
  parseAssociation: function(associationType, associationName, options) {
57
58
  function parseResponseWith(key, response) {
58
59
  var result;
59
- return _([_.str.camelize, _.str.underscored]).any(function(fn) {
60
+ return _.any([_.str.camelize, _.str.underscored], function(fn) {
60
61
  var k = fn(key);
61
62
  return (result = response[k] && {key: k, response: response[k]});
62
63
  }) && result || {response: null};
63
64
  }
64
65
 
65
66
  function through(response) {
66
- var t = parseResponseWith(_(options).result('through'), response).response,
67
- singularAssociationName = _.singularize && _(associationName).singularize(),
67
+ var t = parseResponseWith(_.result(options, 'through'), response).response,
68
+ singularAssociationName = _.singularize && _.singularize(associationName),
68
69
  p = options.parseName || singularAssociationName;
69
- return {response: t && p && _(t)[associationType === 'hasOne' ? 'result' : 'pluck'](p)};
70
+ return {response: t && p && _[associationType === 'hasOne' && 'result' || 'pluck'](t, p)};
70
71
  }
71
72
 
72
73
  if (options.parse) {
73
- if (!_(this).has('_parsers')) {
74
+ if (!_.has(this, '_parsers')) {
74
75
  this._parsers = [];
75
76
  }
76
77
 
@@ -85,14 +86,13 @@
85
86
 
86
87
  if (associations[associationType]) {
87
88
  var parsers = this._parsers;
88
- if (_(parsers).isEmpty()) {
89
- this.prototype.parse = _(this.prototype.parse).wrap(function(oldParse, response) {
89
+ if (_.isEmpty(parsers)) {
90
+ this.prototype.parse = _.wrap(this.prototype.parse, function(oldParse, response) {
90
91
  var self = this;
91
- return _(oldParse.call(self, response)).tap(function(parsedResponse) {
92
- _(parsers)
93
- .chain()
92
+ return _.tap(oldParse.call(self, response), function(parsedResponse) {
93
+ _.chain(parsers)
94
94
  .map(function(parser) {
95
- return _(parser.parseFn.call(self).call(self, parsedResponse)).tap(function(result) {
95
+ return _.tap(parser.parseFn.call(self).call(self, parsedResponse), function(result) {
96
96
  parser.associationFn.call(self, result.response);
97
97
  }).key;
98
98
  })
@@ -105,7 +105,7 @@
105
105
 
106
106
  this._parsers.push({
107
107
  parseFn: function() {
108
- return _(options.parse).isFunction() &&
108
+ return _.isFunction(options.parse) &&
109
109
  function(response) { return {response: options.parse.call(this, response) }; } ||
110
110
  function(response) {
111
111
  return (options.through && through.call(this, response)) ||
@@ -126,12 +126,12 @@
126
126
 
127
127
  return {
128
128
  included: function(source) {
129
- var associations = _({
129
+ var associations = _.reduce({
130
130
  belongsTo: {}, hasMany: {parse: true}, hasOne: {parse: true}
131
- }).reduce(function(associations, defaultOptions, associationType) {
131
+ }, function(associations, defaultOptions, associationType) {
132
132
  associations[associationType] = function(name, options) {
133
133
  var associationName = _.str.camelize(name);
134
- options = _({}).extend(defaultOptions, globalOptions, options);
134
+ options = _.extend({}, defaultOptions, globalOptions, options);
135
135
  fn.buildAssociation.call(this, namespace, associationType, associationName, options);
136
136
  fn.parseAssociation.call(this, associationType, associationName, options);
137
137
  return this;
@@ -139,30 +139,30 @@
139
139
  return associations;
140
140
  }, {});
141
141
 
142
- _(source).extend(associations, {
142
+ _.extend(source, associations, {
143
143
  associations: function() {
144
144
  var self = this;
145
- _(arguments).chain().toArray().compact().each(function(options) {
146
- _(associations).chain().keys().each(function(associationType) {
145
+ _.chain(arguments).toArray().compact().each(function(options) {
146
+ _.chain(associations).keys().each(function(associationType) {
147
147
  if (options[associationType]) {
148
- associations[associationType].call(self, options[associationType], _(options).omit(associationType));
148
+ associations[associationType].call(self, options[associationType], _.omit(options, associationType));
149
149
  }
150
150
  });
151
151
  });
152
152
  },
153
153
 
154
- extend: _(source.extend).wrap(function(oldExtend, protoProps, classProps) {
155
- return _(oldExtend.call(this, protoProps, classProps)).tap(function(Klass) {
154
+ extend: _.wrap(source.extend, function(oldExtend, protoProps, classProps) {
155
+ return _.tap(oldExtend.call(this, protoProps, classProps), function(Klass) {
156
156
  var args = (protoProps || {}).associations;
157
157
  if (args) {
158
- Klass.associations.apply(Klass, _([args]).flatten());
158
+ Klass.associations.apply(Klass, _.flatten([args]));
159
159
  }
160
160
  });
161
161
  })
162
162
  });
163
163
 
164
- source.prototype.initialize = _(source.prototype.initialize).wrap(function(oldInitialize, attrsOrModels, options) {
165
- this._options = this._options || _(options).clone();
164
+ source.prototype.initialize = _.wrap(source.prototype.initialize, function(oldInitialize, attrsOrModels, options) {
165
+ this._options = this._options || _.clone(options);
166
166
  oldInitialize.call(this, attrsOrModels, options);
167
167
  });
168
168
  }
@@ -170,5 +170,5 @@
170
170
  }
171
171
  mixin.fn = fn;
172
172
 
173
- Backbone.extensions = _(Backbone.extensions || {}).extend({associations: mixin});
174
- }).call(this, _, Backbone);
173
+ Backbone.extensions = _.extend(Backbone.extensions || {}, {associations: mixin});
174
+ }).call(this);
@@ -1,5 +1,6 @@
1
- (function(_, Backbone) {
1
+ (function() {
2
2
  'use strict';
3
+ var exports = this, _ = exports._, Backbone = exports.Backbone;
3
4
  function Decorator(models, options) {
4
5
  this._decoratee = models instanceof Backbone.Collection ? models.models : models;
5
6
  this.initialize.call(this, models, options);
@@ -8,8 +9,8 @@
8
9
  function wrapDecorator(fnName) {
9
10
  return function() {
10
11
  var Klass = this.constructor, args = arguments;
11
- if (_(this._decoratee).isArray()) {
12
- return _(this._decoratee).map(function(model) {
12
+ if (_.isArray(this._decoratee)) {
13
+ return _.map(this._decoratee, function(model) {
13
14
  return (Klass.fn[fnName]).apply(model, args);
14
15
  });
15
16
  } else {
@@ -18,17 +19,15 @@
18
19
  };
19
20
  }
20
21
 
21
- _(Decorator).extend({
22
+ _.extend(Decorator, {
22
23
  extend: function(protoProps, classProps) {
23
- var proto = _(protoProps)
24
- .chain()
25
- .omit('collection', 'constructor', 'initialize', 'model'),
24
+ var proto = _.chain(protoProps).omit('collection', 'constructor', 'initialize', 'model'),
26
25
  wrapped = proto.reduce(function(proto, fn, name) {
27
26
  return (proto[name] = wrapDecorator(name)) && proto;
28
27
  }, {}).value();
29
28
  this.fn = proto.value();
30
- return _(Backbone.Model.extend.call(this, _(protoProps).extend(wrapped), classProps)).tap(function(Klass) {
31
- _(['model', 'collection']).each(function(type) {
29
+ return _.tap(Backbone.Model.extend.call(this, _.extend(protoProps, wrapped), classProps), function(Klass) {
30
+ _.each(['model', 'collection'], function(type) {
32
31
  if (protoProps[type]) {
33
32
  protoProps[type].prototype.decorator = function() {
34
33
  return new Klass(this);
@@ -39,9 +38,9 @@
39
38
  }
40
39
  }, Backbone.extensions && Backbone.extensions.include || {});
41
40
 
42
- _(Decorator.prototype).extend({
41
+ _.extend(Decorator.prototype, {
43
42
  initialize: function(models, options) {}
44
43
  });
45
44
 
46
- Backbone.extensions = _(Backbone.extensions || {}).extend({Decorator: Decorator});
47
- }).call(this, _, Backbone);
45
+ Backbone.extensions = _.extend(Backbone.extensions || {}, {Decorator: Decorator});
46
+ }).call(this);
@@ -1,13 +1,14 @@
1
- (function(_, Backbone) {
1
+ (function() {
2
2
  'use strict';
3
+ var exports = this, _ = exports._, Backbone = exports.Backbone;
3
4
  function bindModelEvents(tuple) {
4
5
  var self = this, subject = tuple[0], eventNames = tuple[1], isJquery = !!_(subject).result('jquery'),
5
6
  modelEvents = self._modelCallbacks, context = tuple[2];
6
7
  modelEvents.push(tuple);
7
- _(subject && eventNames).each(function(callback, event) {
8
- _(event.split(' ')).each(function(e) {
9
- _([callback]).chain().flatten().each(function(c) {
10
- var fn = _(c).isFunction() ? c : self[c];
8
+ _.each(subject && eventNames, function(callback, event) {
9
+ _.each(event.split(' '), function(e) {
10
+ _.chain([callback]).flatten().each(function(c) {
11
+ var fn = _.isFunction(c) ? c : self[c];
11
12
  if (isJquery) {
12
13
  if (context) {
13
14
  subject.on(e, context, fn);
@@ -24,12 +25,12 @@
24
25
 
25
26
  function unbindModelEvents() {
26
27
  var self = this, modelEvents = self._modelCallbacks;
27
- _(modelEvents).each(function(tuple) {
28
- var subject = tuple[0], events = tuple[1], context = tuple[2], isJquery = !!_(subject).result('jquery');
29
- _(subject && events).each(function(callback, event) {
30
- _(event.split(' ')).each(function(e) {
31
- _([callback]).chain().flatten().each(function(c) {
32
- var fn = _(c).isFunction() ? c : self[c];
28
+ _.each(modelEvents, function(tuple) {
29
+ var subject = tuple[0], events = tuple[1], context = tuple[2], isJquery = !!_.result(subject, 'jquery');
30
+ _.each(subject && events, function(callback, event) {
31
+ _.each(event.split(' '), function(e) {
32
+ _.chain([callback]).flatten().each(function(c) {
33
+ var fn = _.isFunction(c) ? c : self[c];
33
34
  if (isJquery) {
34
35
  if (context) {
35
36
  subject.off(e, context, fn);
@@ -55,27 +56,28 @@
55
56
 
56
57
  var delegateEvents = {
57
58
  included: function(source) {
58
- _(source.prototype).extend({
59
- initialize: _(source.prototype.initialize).wrap(function(oldInitialize, attrsOrModels, options) {
59
+ _.extend(source.prototype, {
60
+ initialize: _.wrap(source.prototype.initialize, function(oldInitialize, attrsOrModels, options) {
60
61
  this._modelCallbacks = [];
61
62
  oldInitialize.call(this, attrsOrModels, options);
62
63
  }),
63
64
 
64
- delegateEvents: _(source.prototype.delegateEvents).wrap(function(oldDelegateEvents) {
65
- var self = this, args = _(arguments).rest();
65
+ delegateEvents: _.wrap(source.prototype.delegateEvents, function(oldDelegateEvents) {
66
+ var self = this, args = _.rest(arguments);
66
67
 
67
68
  if (!args.length) {
68
69
  return oldDelegateEvents.call(this);
69
70
  }
71
+
70
72
  wrapUndelegateEvents.call(this, function() {
71
- _(args).chain().toArray().compact().each(function(obj) {
73
+ _.chain(args).toArray().compact().each(function(obj) {
72
74
  var arg = _(obj);
73
75
  if (arg.isArray()) {
74
76
  bindModelEvents.call(self, obj);
75
77
  } else {
76
78
  arg.each(function(callbacks, event) {
77
- _([callbacks]).chain().flatten().each(function(callback) {
78
- oldDelegateEvents.call(self, _({}).tap(function(obj) {
79
+ _.chain([callbacks]).flatten().each(function(callback) {
80
+ oldDelegateEvents.call(self, _.tap({}, function(obj) {
79
81
  obj[event] = callback;
80
82
  }));
81
83
  });
@@ -85,12 +87,12 @@
85
87
  });
86
88
  }),
87
89
 
88
- undelegateEvents: _(source.prototype.undelegateEvents).wrap(function(oldUndelegateEvents) {
90
+ undelegateEvents: _.wrap(source.prototype.undelegateEvents, function(oldUndelegateEvents) {
89
91
  unbindModelEvents.call(this);
90
92
  return oldUndelegateEvents.call(this);
91
93
  }),
92
94
 
93
- remove: _(source.prototype.remove).wrap(function(oldRemove) {
95
+ remove: _.wrap(source.prototype.remove, function(oldRemove) {
94
96
  this.undelegateEvents();
95
97
  return oldRemove.call(this);
96
98
  })
@@ -98,5 +100,5 @@
98
100
  }
99
101
  };
100
102
 
101
- Backbone.extensions = _(Backbone.extensions || {}).extend({delegateEvents: delegateEvents});
102
- }).call(this, _, Backbone);
103
+ Backbone.extensions = _.extend(Backbone.extensions || {}, {delegateEvents: delegateEvents});
104
+ }).call(this);
@@ -1,10 +1,11 @@
1
- (function(_, Backbone) {
1
+ (function() {
2
2
  'use strict';
3
+ var exports = this, _ = exports._, Backbone = exports.Backbone;
3
4
  var include = {
4
5
  include: function() {
5
6
  var self = this;
6
- _(arguments).chain().toArray().each(function(module) {
7
- if (module && module.included && _(module.included).isFunction()) {
7
+ _.chain(arguments).toArray().each(function(module) {
8
+ if (module && module.included && _.isFunction(module.included)) {
8
9
  module.included(self);
9
10
  }
10
11
  });
@@ -12,5 +13,5 @@
12
13
  }
13
14
  };
14
15
 
15
- Backbone.extensions = _(Backbone.extensions || {}).extend({include: include});
16
- }).call(this, _, Backbone);
16
+ Backbone.extensions = _.extend(Backbone.extensions || {}, {include: include});
17
+ }).call(this);
@@ -1,3 +1,3 @@
1
1
  module BackboneExtensions
2
- VERSION = '0.0.23'
2
+ VERSION = '0.0.24'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backbone_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.23
4
+ version: 0.0.24
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-13 00:00:00.000000000 Z
13
+ date: 2013-03-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fuubar
@@ -35,7 +35,7 @@ dependencies:
35
35
  requirements:
36
36
  - - ! '>='
37
37
  - !ruby/object:Gem::Version
38
- version: 1.2.1
38
+ version: 1.3.2
39
39
  type: :development
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  requirements:
44
44
  - - ! '>='
45
45
  - !ruby/object:Gem::Version
46
- version: 1.2.1
46
+ version: 1.3.2
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jshint_on_rails
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -76,6 +76,22 @@ dependencies:
76
76
  - - ! '>='
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: yajl-ruby
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
79
95
  - !ruby/object:Gem::Dependency
80
96
  name: rails
81
97
  requirement: !ruby/object:Gem::Requirement
@@ -126,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
142
  version: '0'
127
143
  segments:
128
144
  - 0
129
- hash: 4389807345042330580
145
+ hash: 3920379791586607175
130
146
  required_rubygems_version: !ruby/object:Gem::Requirement
131
147
  none: false
132
148
  requirements:
@@ -135,10 +151,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
151
  version: '0'
136
152
  segments:
137
153
  - 0
138
- hash: 4389807345042330580
154
+ hash: 3920379791586607175
139
155
  requirements: []
140
156
  rubyforge_project:
141
- rubygems_version: 1.8.21
157
+ rubygems_version: 1.8.24
142
158
  signing_key:
143
159
  specification_version: 3
144
160
  summary: Extensions to backbone javascript library as a rails engine