backbone-support 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ before_install:
3
+ - 'export DISPLAY=:99.0'
4
+ - 'sh -e /etc/init.d/xvfb start'
5
+ rvm:
6
+ - '1.9.2'
7
+ - '1.9.3'
data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ 0.3.2 (April 27, 2013)
2
+
3
+ - Backbone support now includes a vendored version of Backbone and Underscore
4
+ for use with the asset pipeline.
5
+ - SwappingRouter now calls 'swapped' method on new view as it is added to the
6
+ DOM. CompositeView emits an associated 'swapped' event.
7
+ - CompositeView#prependChildTo is now properly scoped to the view thanks to nhocki
8
+ - Backbone Support is now on Travis for continuous integration
9
+
1
10
  0.3.1 (March 05, 2013)
2
11
 
3
12
  Views fire 'leave' event when calling leave()
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
- gem 'jasmine'
4
- gem 'headless'
5
- gem 'rake'
3
+ gemspec
@@ -1,38 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ backbone-support (0.3.2)
5
+
1
6
  GEM
2
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
3
8
  specs:
4
- childprocess (0.2.0)
5
- ffi (~> 1.0.6)
6
- diff-lcs (1.1.2)
7
- ffi (1.0.9)
8
- headless (0.1.0)
9
- jasmine (1.0.2.1)
10
- json_pure (>= 1.4.3)
11
- rack (>= 1.1)
9
+ childprocess (0.3.9)
10
+ ffi (~> 1.0, >= 1.0.11)
11
+ diff-lcs (1.2.1)
12
+ ffi (1.4.0)
13
+ headless (1.0.1)
14
+ jasmine (1.3.0)
15
+ jasmine-core (>= 1.3.0)
16
+ rack (~> 1.0)
12
17
  rspec (>= 1.3.1)
13
18
  selenium-webdriver (>= 0.1.3)
14
- json_pure (1.5.3)
15
- rack (1.3.2)
16
- rake (0.9.2)
17
- rspec (2.6.0)
18
- rspec-core (~> 2.6.0)
19
- rspec-expectations (~> 2.6.0)
20
- rspec-mocks (~> 2.6.0)
21
- rspec-core (2.6.4)
22
- rspec-expectations (2.6.0)
23
- diff-lcs (~> 1.1.2)
24
- rspec-mocks (2.6.0)
25
- rubyzip (0.9.4)
26
- selenium-webdriver (2.3.2)
27
- childprocess (>= 0.1.9)
28
- ffi (>= 1.0.7)
29
- json_pure
19
+ jasmine-core (1.3.1)
20
+ multi_json (1.6.1)
21
+ rack (1.5.2)
22
+ rake (10.0.3)
23
+ rspec (2.13.0)
24
+ rspec-core (~> 2.13.0)
25
+ rspec-expectations (~> 2.13.0)
26
+ rspec-mocks (~> 2.13.0)
27
+ rspec-core (2.13.0)
28
+ rspec-expectations (2.13.0)
29
+ diff-lcs (>= 1.1.3, < 2.0)
30
+ rspec-mocks (2.13.0)
31
+ rubyzip (0.9.9)
32
+ selenium-webdriver (2.31.0)
33
+ childprocess (>= 0.2.5)
34
+ multi_json (~> 1.0)
30
35
  rubyzip
36
+ websocket (~> 1.0.4)
37
+ websocket (1.0.7)
31
38
 
32
39
  PLATFORMS
33
40
  ruby
34
41
 
35
42
  DEPENDENCIES
43
+ backbone-support!
36
44
  headless
37
- jasmine
45
+ jasmine (= 1.3.0)
38
46
  rake
data/README.md CHANGED
@@ -1,12 +1,18 @@
1
- There's no built-in garbage collection for Backbone’s event bindings, and
2
- forgetting to unbind can cause bugs and memory leaks.
1
+ # Backbone Support
3
2
 
4
- Backbone Support currently provides two utility classes, SwappingRouter and CompositeView,
5
- that introduce a `leave()` function, which unbinds and cleans up the view.
6
- They should be used where views are instantiated (in Router instances and in composite views).
3
+ [![Build Status](https://travis-ci.org/thoughtbot/backbone-support.png?branch=master)](https://travis-ci.org/thoughtbot/backbone-support)
7
4
 
8
- Inspired by our projects and the Backbone.js on Rails book:
9
- http://workshops.thoughtbot.com/backbone-js-on-rails
5
+ Backbone Support provides a collection of utility classes for use with
6
+ [Backbone.js][]. There's no built-in garbage collection for Backbone’s event
7
+ bindings, and forgetting to unbind can cause bugs and memory leaks. Backbone
8
+ Support has your covered.
9
+
10
+ Backbone Support currently provides two utility classes, SwappingRouter and
11
+ CompositeView, that introduce a `leave()` function, which unbinds and cleans up
12
+ the view. They should be used where views are instantiated (in Router
13
+ instances and in composite views).
14
+
15
+ Inspired by our projects and the [Backbone.js on Rails book][].
10
16
 
11
17
  The book contains complete instructions and in-depth coverage of the internals
12
18
  of CompositeView and SwappingRouter, and an example application that shows
@@ -68,7 +74,7 @@ parent view.
68
74
 
69
75
  `CompositeView` maintains an array of its immediate children as
70
76
  `this.children`. Using this reference, a parent view's `leave()`
71
- method will invoke `leave()` on all its children, ensuring that an entire
77
+ method will invoke `leave()` on all its children, ensuring that an entire
72
78
  tree of composed views is cleaned up properly.
73
79
 
74
80
  For child views that can dismiss themselves, such as dialog boxes, children
@@ -77,31 +83,33 @@ maintain a back-reference at `this.parent`. This is used to reach up and call
77
83
 
78
84
  ## Dependencies
79
85
 
80
- You'll need these, but chances are you already have them in your app:
86
+ Backbone Support has the following dependencies:
81
87
 
82
88
  * jQuery or Zepto
83
89
  * Underscore
84
90
  * Backbone
85
91
 
86
- ## Development
87
-
88
- First:
89
-
90
- bundle
91
-
92
- While TDD'ing:
92
+ ### Included Versions
93
93
 
94
- bundle exec rake jasmine
94
+ For convenience, Backbone Support comes with a vendored copy of Backbone and
95
+ Underscore to get you up and running as quickly as possible. If you want to
96
+ use these included files, simply follow the instructions below in the
97
+ [Installation][] section.
95
98
 
96
- To not open tests in a browser window:
99
+ ### Alternate Versions
97
100
 
98
- bundle exec rake jasmine:ci
101
+ If you require a different version of Backbone or Underscore than those
102
+ provided by this gem, simply put the script files in
103
+ `vendor/assets/javascripts` and they will take higher precedence than the
104
+ versions provided by the gem thanks to the ordering of the [search paths in the
105
+ asset pipeline][].
99
106
 
100
107
  ## Installation
101
108
 
102
- The recommended usage is with Rails 3.1.
109
+ The recommended usage is with Rails 3.1 or higher to take advantage of the
110
+ asset pipeline.
103
111
 
104
- ### With Rails 3.1
112
+ ### With Rails 3.1 or higher
105
113
 
106
114
  Add the gem to your Gemfile
107
115
 
@@ -109,8 +117,19 @@ Add the gem to your Gemfile
109
117
 
110
118
  And then `bundle install`
111
119
 
112
- In your application.js, or in whatever file your backbone.js assets are
113
- required in, add the following:
120
+ Before including any part of Backbone Support, you must include its
121
+ dependencies. In your application.js or any other manifest file, add the
122
+ following to load in the needed dependencies:
123
+
124
+ // jQuery is provided by the 'jquery-rails' gem, included with Rails
125
+ //= require jquery
126
+ //
127
+ // Backbone Support includes Backbone and Underscore, or you can provides
128
+ // alternate versions by placing them in vendor/assets/javascripts/
129
+ //= require backbone
130
+ //= require underscore
131
+
132
+ To require all of Backbone Support, add the following:
114
133
 
115
134
  //= require backbone-support
116
135
 
@@ -118,13 +137,16 @@ This should be _above_ any usage of SwappingController or SwappingRouter, but
118
137
  below the inclusion of Backbone.js, Underscore, and jQuery.
119
138
 
120
139
  If you do not wish to include all of backbone-support, you can include
121
- individual pieces. First, require the main support file:
140
+ individual pieces. Require the support file and the individual assets you
141
+ wish to use:
122
142
 
123
143
  //= require backbone-support/support
144
+ //= require backbone-support/swapping_router
124
145
 
125
- Then require the individual assets you wish to use:
146
+ or:
126
147
 
127
- //= require backbone-support/swapping_router
148
+ //= require backbone-support/support
149
+ //= require backbone-support/observer
128
150
  //= require backbone-support/composite_view
129
151
 
130
152
  ### With Jammit
@@ -175,6 +197,26 @@ require("/vendor/plugins/backbone-support/lib/assets/javascripts/backbone-suppor
175
197
  require("/vendor/plugins/backbone-support/lib/assets/javascripts/backbone-support/swapping_router.js");
176
198
  ```
177
199
 
200
+ ## Development
201
+
202
+ First:
203
+
204
+ bundle
205
+
206
+ While TDD'ing:
207
+
208
+ bundle exec rake jasmine
209
+
210
+ To not open tests in a browser window:
211
+
212
+ bundle exec rake jasmine:ci
213
+
178
214
  ## License
179
215
 
180
- Copyright 2012 thoughtbot. Please check LICENSE for more details.
216
+ Copyright 2012 thoughtbot. Please check [LICENSE][] for more details.
217
+
218
+ [Installation]: https://github.com/thoughtbot/backbone-support#installation
219
+ [search paths in the asset pipeline]: http://edgeguides.rubyonrails.org/asset_pipeline.html#search-paths
220
+ [Backbone.js on Rails book]: https://learn.thoughtbot.com/products/1-backbone-js-on-rails
221
+ [Backbone.js]: http://backbonejs.org/
222
+ [LICENSE]: https://github.com/thoughtbot/backbone-support/blob/master/LICENSE
@@ -16,5 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_development_dependency('jasmine')
19
+ s.add_development_dependency('jasmine', '1.3.0')
20
+ s.add_development_dependency('rake')
21
+ s.add_development_dependency('headless')
20
22
  end
@@ -41,7 +41,11 @@ _.extend(Support.CompositeView.prototype, Backbone.View.prototype, Support.Obser
41
41
 
42
42
  prependChildTo: function (view, container) {
43
43
  this.renderChild(view);
44
- $(container).prepend(view.el);
44
+ this.$(container).prepend(view.el);
45
+ },
46
+
47
+ swapped: function () {
48
+ this.trigger('swapped')
45
49
  },
46
50
 
47
51
  _leaveChildren: function() {
@@ -1,2 +1,2 @@
1
- Support = {};
2
- Support.VERSION = "0.0.1";
1
+ window.Support = {};
2
+ Support.VERSION = "0.3.2";
@@ -10,6 +10,10 @@ _.extend(Support.SwappingRouter.prototype, Backbone.Router.prototype, {
10
10
 
11
11
  this.currentView = newView;
12
12
  $(this.el).empty().append(this.currentView.render().el);
13
+
14
+ if (this.currentView && this.currentView.swapped) {
15
+ this.currentView.swapped();
16
+ }
13
17
  }
14
18
  });
15
19
 
@@ -1,3 +1,3 @@
1
1
  module BackboneSupport
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.3.2'.freeze
3
3
  end
@@ -91,6 +91,15 @@ describe("Support.CompositeView", function() {
91
91
 
92
92
  expect($(view.el).find('.inside').text()).toEqual("Append to this!Orange!");
93
93
  });
94
+
95
+ it("appends the element only to elements inside the view", function(){
96
+ var view = new blankView({el: $('<div><div class="main">Append to this!</div></div>')});
97
+ var div = $("<div class='main' id='outside'></div>");
98
+ view.appendChildTo(new orangeView(), ".main");
99
+
100
+ expect($(view.el).find('.main').text()).toEqual("Append to this!Orange!");
101
+ expect($("#outside").text()).toEqual("");
102
+ });
94
103
  });
95
104
 
96
105
  describe("#prependChild", function() {
@@ -108,11 +117,29 @@ describe("Support.CompositeView", function() {
108
117
  $("#test1").text("Prepend to this!");
109
118
 
110
119
  var view = new blankView({el: "#test"});
120
+ expect($("#test").text()).toEqual("");
121
+
122
+ $("#test").append($("#test1"));
111
123
  view.prependChildTo(new orangeView(), "#test1");
112
124
 
113
- expect($("#test").text()).toEqual("");
114
125
  expect($("#test1").text()).toEqual("Orange!Prepend to this!");
115
126
  });
127
+
128
+ it("prepends child into a sub-element even if it is not added to the document", function() {
129
+ var view = new blankView({el: $('<div><div class="inside">Prepend to this!</div></div>')});
130
+ view.prependChildTo(new orangeView(), ".inside");
131
+
132
+ expect($(view.el).find('.inside').text()).toEqual("Orange!Prepend to this!");
133
+ });
134
+
135
+ it("prepends the element only to elements inside the view", function(){
136
+ var view = new blankView({el: $('<div><div class="main">Prepend to this!</div></div>')});
137
+ var div = $("<div class='main' id='outside'></div>");
138
+ view.prependChildTo(new orangeView(), ".main");
139
+
140
+ expect($(view.el).find('.main').text()).toEqual("Orange!Prepend to this!");
141
+ expect($("#outside").text()).toEqual("");
142
+ });
116
143
  });
117
144
 
118
145
  describe("#leave", function() {
@@ -219,6 +246,18 @@ describe("Support.CompositeView", function() {
219
246
  });
220
247
  });
221
248
 
249
+ describe("#swapped", function() {
250
+ it("fires 'swapped' event", function() {
251
+ var eventListener = sinon.spy()
252
+ var view = new Support.CompositeView
253
+ view.bind('swapped', eventListener)
254
+
255
+ view.swapped();
256
+
257
+ expect(eventListener.called).toBeTruthy();
258
+ });
259
+ });
260
+
222
261
  describe("#bindTo", function() {
223
262
  var view = new orangeView();
224
263
  var callback = sinon.spy();
@@ -260,5 +299,4 @@ describe("Support.CompositeView", function() {
260
299
  });
261
300
  });
262
301
  });
263
-
264
302
  });
@@ -11,9 +11,9 @@
11
11
  # - dist/**/*.js
12
12
  #
13
13
  src_files:
14
- - vendor/jquery.js
15
- - vendor/underscore.js
16
- - vendor/backbone.js
14
+ - spec/javascripts/support/jquery.js
15
+ - vendor/assets/javascripts/underscore.js
16
+ - vendor/assets/javascripts/backbone.js
17
17
  - lib/assets/javascripts/backbone-support.js
18
18
  - lib/assets/javascripts/backbone-support/support.js
19
19
  - lib/assets/javascripts/backbone-support/observer.js
@@ -16,8 +16,8 @@ describe("Support.SwappingRouter", function() {
16
16
  });
17
17
 
18
18
  var leaveView = Backbone.View.extend({
19
- leave: function() {
20
- }
19
+ leave: function() {},
20
+ swapped: function() {},
21
21
  });
22
22
  var leaveViewInstance = new leaveView();
23
23
 
@@ -119,4 +119,18 @@ describe("Support.SwappingRouter", function() {
119
119
  expect(spy.called).toBeTruthy();
120
120
  });
121
121
  });
122
+
123
+ it("calls .swapped on the view after swapping", function() {
124
+ var spy = sinon.spy(leaveViewInstance, "swapped");
125
+
126
+ runs(function() {
127
+ window.location.hash = "#leave"
128
+ });
129
+
130
+ Helpers.sleep()
131
+
132
+ runs(function() {
133
+ expect(spy.called).toBeTruthy()
134
+ });
135
+ });
122
136
  });
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backbone-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,10 +12,42 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-03-05 00:00:00.000000000 Z
15
+ date: 2013-05-10 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: jasmine
19
+ requirement: !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - '='
23
+ - !ruby/object:Gem::Version
24
+ version: 1.3.0
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - '='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.3.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ - !ruby/object:Gem::Dependency
50
+ name: headless
19
51
  requirement: !ruby/object:Gem::Requirement
20
52
  none: false
21
53
  requirements:
@@ -38,6 +70,7 @@ extensions: []
38
70
  extra_rdoc_files: []
39
71
  files:
40
72
  - .gitignore
73
+ - .travis.yml
41
74
  - CHANGELOG
42
75
  - Gemfile
43
76
  - Gemfile.lock
@@ -60,10 +93,10 @@ files:
60
93
  - spec/javascripts/support/jasmine.yml
61
94
  - spec/javascripts/support/jasmine_config.rb
62
95
  - spec/javascripts/support/jasmine_runner.rb
96
+ - spec/javascripts/support/jquery.js
63
97
  - spec/javascripts/swapping_router_spec.js
64
- - vendor/backbone.js
65
- - vendor/jquery.js
66
- - vendor/underscore.js
98
+ - vendor/assets/javascripts/backbone.js
99
+ - vendor/assets/javascripts/underscore.js
67
100
  homepage: http://github.com/thoughtbot/backbone-support
68
101
  licenses: []
69
102
  post_install_message:
@@ -84,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
117
  version: '0'
85
118
  requirements: []
86
119
  rubyforge_project:
87
- rubygems_version: 1.8.23
120
+ rubygems_version: 1.8.25
88
121
  signing_key:
89
122
  specification_version: 3
90
123
  summary: SwappingController and CompositeView for Backbone.js
@@ -96,5 +129,5 @@ test_files:
96
129
  - spec/javascripts/support/jasmine.yml
97
130
  - spec/javascripts/support/jasmine_config.rb
98
131
  - spec/javascripts/support/jasmine_runner.rb
132
+ - spec/javascripts/support/jquery.js
99
133
  - spec/javascripts/swapping_router_spec.js
100
- has_rdoc: