pusher_rails 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ v0.1.2
2
+ ======
3
+ - Added dependency to pusher (~>0.8.2)
4
+ - Added backpusher.js to asset pipeline.
5
+
6
+ v0.1.1
7
+ ======
8
+ - added an empty Rails Engine so assets get served. d'oh!
data/README.md CHANGED
@@ -1,9 +1,36 @@
1
- Pusher for Rails 3.1+
1
+ [Pusher](https://pusher.com) for Rails 3.1+
2
2
  =====================
3
3
 
4
- Adds the javascript needed to use [Pusher](https://pusher.com) in your rails 3.1 app.
4
+ Adds:
5
+ - [pusher-gem v0.8.2](https://github.com/pusher/pusher-gem/tree/v0.8.2)
6
+ - [pusher.js v1.9.1](https://github.com/pusher/pusher-js/tree/v1.9.1)
7
+ - [backpusher.js](https://github.com/pusher/backpusher/commit/e61c9d7a761fcb48f312416408d1bf4ed418735b#diff-1)
8
+
9
+ This pulls in the *pusher-gem* as well as adding *pusher.js* and *backpusher.js* to the assets pipeline of your rails 3.1 app.
5
10
 
6
11
  Add this to your app/assets/javascripts/application.js:
7
12
 
8
- //=require pusher
13
+ // if you want to use pusher.js
14
+ //= require pusher
15
+
16
+ // if you are using pusher.js + backbone.js
17
+ //= require backpusher
18
+
19
+
20
+ Licenses
21
+ ========
9
22
 
23
+ /*
24
+ * Pusher JavaScript Library v1.9.1
25
+ * http://pusherapp.com/
26
+ *
27
+ * Copyright 2011, Pusher
28
+ * Released under the MIT licence.
29
+ */
30
+
31
+ // Backpusher.js 0.0.1
32
+ // (c) 2011 Pusher.
33
+ // Backpusher may be freely distributed under the MIT license.
34
+ // For all details and documentation:
35
+ // http://github.com/pusher/backpusher
36
+
data/pusher_rails.gemspec CHANGED
@@ -1,11 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
1
4
  Gem::Specification.new do |s|
2
- s.name = 'pusher_rails'
3
- s.version = '0.1.1'
4
- s.author = 'David Grandinetti'
5
- s.email = 'dave@wegoto12.com'
6
- s.summary = 'Pusher integration for Rails 3.1+'
7
- s.description = 'Adds pusher.js to the asset pipeline'
8
- s.homepage = 'https://github.com/dbgrandi/pusher_rails'
5
+ s.name = 'pusher_rails'
6
+ s.version = '0.1.2'
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["David Grandinetti"]
9
+ s.email = ["dave@wegoto12.com"]
10
+ s.summary = 'Pusher integration for Rails 3.1+'
11
+ s.description = 'Adds pusher.js/backpusher.js to the asset pipeline and pusher-gemto to your app.'
12
+ s.homepage = 'https://github.com/dbgrandi/pusher_rails'
13
+
14
+ s.add_dependency "pusher", "~> 0.8.2"
9
15
 
10
- s.files = Dir["#{File.dirname(__FILE__)}/**/*"]
16
+ s.files = `git ls-files`.split("\n")
17
+ s.require_paths = ["lib"]
11
18
  end
@@ -0,0 +1,157 @@
1
+ // Backpusher.js 0.0.1
2
+ // (c) 2011 Pusher.
3
+ // Backpusher may be freely distributed under the MIT license.
4
+ // For all details and documentation:
5
+ // http://github.com/pusher/backpusher
6
+
7
+ ;(function(exports, undefined){
8
+ // The top-level namespace. All public Backbone classes and modules will
9
+ // be attached to this. Exported for both CommonJS and the browser.
10
+ var Backpusher = function(channel, collection, options) {
11
+ if (!(this instanceof Backpusher)) {
12
+ return new Backpusher(channel, collection, options);
13
+ }
14
+
15
+ // Bind for the connection established, so
16
+ // we can setup the socket_id param.
17
+ if (channel.pusher.connection) {
18
+ channel.pusher.connection.bind('connected', function() {
19
+ Backbone.pusher_socket_id = channel.pusher.socket_id;
20
+ });
21
+ } else {
22
+ channel.pusher.bind('pusher:connection_established', function() {
23
+ Backbone.pusher_socket_id = channel.pusher.socket_id;
24
+ });
25
+ }
26
+
27
+ // Options is currently unused:
28
+ this.options = (options || {});
29
+ this.channel = channel;
30
+ this.collection = collection;
31
+
32
+ if (this.options.events) {
33
+ this.events = this.options.events;
34
+ } else {
35
+ this.events = Backpusher.defaultEvents;
36
+ }
37
+
38
+ this._bindEvents();
39
+ this.initialize(channel, collection, options);
40
+ };
41
+
42
+ _.extend(Backpusher.prototype, Backbone.Events, {
43
+ initialize: function() {},
44
+
45
+ _bindEvents: function() {
46
+ if (!this.events) return;
47
+
48
+ for (var event in this.events) {
49
+ this.channel.bind(event, _.bind(this.events[event], this));
50
+ }
51
+ },
52
+
53
+ _add: function(model) {
54
+ var Collection = this.collection;
55
+ model = new Collection.model(model);
56
+
57
+ Collection.add(model);
58
+ this.trigger('remote_create', model);
59
+
60
+ return model;
61
+ }
62
+ });
63
+
64
+ Backpusher.defaultEvents = {
65
+ created: function(pushed_model) {
66
+ return this._add(pushed_model);
67
+ },
68
+
69
+ updated: function(pushed_model) {
70
+ var model = this.collection.get(pushed_model);
71
+
72
+ if (model) {
73
+ model = model.set(pushed_model);
74
+
75
+ this.trigger('remote_update', model);
76
+
77
+ return model;
78
+ } else {
79
+ return this._add(pushed_model);
80
+ }
81
+ },
82
+
83
+ destroyed: function(pushed_model) {
84
+ var model = this.collection.get(pushed_model);
85
+
86
+ if (model) {
87
+ this.collection.remove(model);
88
+ this.trigger('remote_destroy', model);
89
+
90
+ return model;
91
+ }
92
+ }
93
+ };
94
+
95
+ // Map from CRUD to HTTP for our default `Backbone.sync` implementation.
96
+ var methodMap = {
97
+ 'create': 'POST',
98
+ 'update': 'PUT',
99
+ 'delete': 'DELETE',
100
+ 'read' : 'GET'
101
+ };
102
+
103
+ // Backpusher's Backbone.sync method:
104
+ // -------------
105
+ Backbone.sync = function(method, model, success, error) {
106
+ var type = methodMap[method];
107
+ var modelJSON = null;
108
+
109
+ if (method === 'create' || method === 'update') {
110
+ modelJSON = JSON.stringify(model.toJSON());
111
+ }
112
+
113
+ if (!(model && model.url)) {
114
+ throw new Error("A 'url' property or function must be specified");
115
+ }
116
+
117
+ var modelUrl = _.isFunction(model.url) ? model.url() : model.url;
118
+ modelUrl += '?socket_id=' + Backbone.pusher_socket_id;
119
+
120
+ // Default JSON-request options.
121
+ var params = {
122
+ url: modelUrl,
123
+ type: type,
124
+ contentType: 'application/json',
125
+ data: modelJSON,
126
+ dataType: 'json',
127
+ processData: false,
128
+ success: success,
129
+ error: error
130
+ };
131
+
132
+ // For older servers, emulate JSON by encoding the request into an HTML-form.
133
+ if (Backbone.emulateJSON) {
134
+ params.contentType = 'application/x-www-form-urlencoded';
135
+ params.processData = true;
136
+ params.data = modelJSON ? {model : modelJSON} : {};
137
+ }
138
+
139
+ // For older servers, emulate HTTP by mimicking the HTTP method with `_method`
140
+ // And an `X-HTTP-Method-Override` header.
141
+ if (Backbone.emulateHTTP) {
142
+ if (type === 'PUT' || type === 'DELETE') {
143
+ if (Backbone.emulateJSON) params.data._method = type;
144
+ params.type = 'POST';
145
+ params.beforeSend = function(xhr) {
146
+ xhr.setRequestHeader("X-HTTP-Method-Override", type);
147
+ };
148
+ }
149
+ }
150
+
151
+ // Make the request.
152
+ $.ajax(params);
153
+ };
154
+
155
+ // Export:
156
+ exports.Backpusher = Backpusher;
157
+ })((typeof exports !== 'undefined' ? exports : this));
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,18 +9,34 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-27 00:00:00.000000000Z
13
- dependencies: []
14
- description: Adds pusher.js to the asset pipeline
15
- email: dave@wegoto12.com
12
+ date: 2011-07-28 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pusher
16
+ requirement: &2156325720 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2156325720
25
+ description: Adds pusher.js/backpusher.js to the asset pipeline and pusher-gemto to
26
+ your app.
27
+ email:
28
+ - dave@wegoto12.com
16
29
  executables: []
17
30
  extensions: []
18
31
  extra_rdoc_files: []
19
32
  files:
20
- - ./lib/pusher_rails.rb
21
- - ./pusher_rails.gemspec
22
- - ./README.md
23
- - ./vendor/assets/javascripts/pusher.js
33
+ - .gitignore
34
+ - CHANGELOG.md
35
+ - README.md
36
+ - lib/pusher_rails.rb
37
+ - pusher_rails.gemspec
38
+ - vendor/assets/javascripts/backpusher.js
39
+ - vendor/assets/javascripts/pusher.js
24
40
  homepage: https://github.com/dbgrandi/pusher_rails
25
41
  licenses: []
26
42
  post_install_message: