sinatra-cometio 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +5 -1
- data/lib/js/cometio.js +1 -43
- data/lib/js/event_emitter.js +61 -0
- data/lib/sinatra-cometio.rb +5 -0
- data/lib/sinatra-cometio/version.rb +2 -2
- data/lib/sinatra/application.rb +5 -3
- data/sample/Gemfile.lock +11 -11
- data/sinatra-cometio.gemspec +2 -2
- metadata +6 -6
- data/Manifest.txt +0 -27
- data/PostInstall.txt +0 -7
data/History.txt
CHANGED
data/lib/js/cometio.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
var CometIO = function(){
|
2
|
+
new EventEmitter().apply(this);
|
2
3
|
this.url = "<%= cometio_url %>";
|
3
4
|
this.session = null;
|
4
5
|
var self = this;
|
@@ -54,47 +55,4 @@ var CometIO = function(){
|
|
54
55
|
}
|
55
56
|
);
|
56
57
|
};
|
57
|
-
|
58
|
-
this.events = new Array();
|
59
|
-
this.on = function(type, listener, opts){
|
60
|
-
if(typeof listener !== "function") return;
|
61
|
-
var event_id = self.events.length > 0 ? 1 + self.events[self.events.length-1].id : 0
|
62
|
-
var params = {
|
63
|
-
id: event_id,
|
64
|
-
type: type,
|
65
|
-
listener: listener
|
66
|
-
};
|
67
|
-
for(i in opts){
|
68
|
-
if(!params[i]) params[i] = opts[i];
|
69
|
-
};
|
70
|
-
self.events.push(params);
|
71
|
-
return event_id;
|
72
|
-
};
|
73
|
-
|
74
|
-
this.once = function(type, listener){
|
75
|
-
this.on(type, listener, {once: true});
|
76
|
-
};
|
77
|
-
|
78
|
-
this.emit = function(type, data){
|
79
|
-
for(var i = 0; i < self.events.length; i++){
|
80
|
-
var e = self.events[i];
|
81
|
-
if(e.type == type) e.listener(data);
|
82
|
-
if(e.once) this.removeListener(e.id);
|
83
|
-
}
|
84
|
-
};
|
85
|
-
|
86
|
-
this.removeListener = function(id_or_type){
|
87
|
-
for(var i = self.events.length-1; i >= 0; i--){
|
88
|
-
var e = self.events[i];
|
89
|
-
switch(typeof id_or_type){
|
90
|
-
case "number":
|
91
|
-
if(e.id == id_or_type) self.events.splice(i,1);
|
92
|
-
break
|
93
|
-
case "string":
|
94
|
-
if(e.type == id_or_type) self.events.splice(i,1);
|
95
|
-
break
|
96
|
-
}
|
97
|
-
}
|
98
|
-
};
|
99
|
-
|
100
58
|
};
|
@@ -0,0 +1,61 @@
|
|
1
|
+
// event_emitter.js v0.0.3
|
2
|
+
// https://github.com/shokai/EventEmitter.js
|
3
|
+
// (c) 2013 Sho Hashimoto <hashimoto@shokai.org>
|
4
|
+
// The MIT License
|
5
|
+
var EventEmitter = function(){
|
6
|
+
var self = this;
|
7
|
+
this.apply = function(target, prefix){
|
8
|
+
if(!prefix) prefix = "";
|
9
|
+
for(var func in self){
|
10
|
+
if(self.hasOwnProperty(func)){
|
11
|
+
target[prefix+func] = this[func];
|
12
|
+
}
|
13
|
+
}
|
14
|
+
};
|
15
|
+
this.__events = new Array();
|
16
|
+
this.on = function(type, listener, opts){
|
17
|
+
if(typeof listener !== "function") return;
|
18
|
+
var event_id = self.__events.length > 0 ? 1 + self.__events[self.__events.length-1].id : 0
|
19
|
+
var params = {
|
20
|
+
id: event_id,
|
21
|
+
type: type,
|
22
|
+
listener: listener
|
23
|
+
};
|
24
|
+
for(i in opts){
|
25
|
+
if(!params[i]) params[i] = opts[i];
|
26
|
+
};
|
27
|
+
self.__events.push(params);
|
28
|
+
return event_id;
|
29
|
+
};
|
30
|
+
|
31
|
+
this.once = function(type, listener){
|
32
|
+
self.on(type, listener, {once: true});
|
33
|
+
};
|
34
|
+
|
35
|
+
this.emit = function(type, data){
|
36
|
+
for(var i = 0; i < self.__events.length; i++){
|
37
|
+
var e = self.__events[i];
|
38
|
+
if(e.type == type) e.listener(data);
|
39
|
+
if(e.once) self.removeListener(e.id);
|
40
|
+
}
|
41
|
+
};
|
42
|
+
|
43
|
+
this.removeListener = function(id_or_type){
|
44
|
+
for(var i = self.__events.length-1; i >= 0; i--){
|
45
|
+
var e = self.__events[i];
|
46
|
+
switch(typeof id_or_type){
|
47
|
+
case "number":
|
48
|
+
if(e.id == id_or_type) self.__events.splice(i,1);
|
49
|
+
break
|
50
|
+
case "string":
|
51
|
+
if(e.type == id_or_type) self.__events.splice(i,1);
|
52
|
+
break
|
53
|
+
}
|
54
|
+
}
|
55
|
+
};
|
56
|
+
|
57
|
+
};
|
58
|
+
|
59
|
+
if(typeof exports !== 'undefined'){
|
60
|
+
exports.EventEmitter = EventEmitter;
|
61
|
+
}
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = '0.0
|
1
|
+
module SinatraCometIO
|
2
|
+
VERSION = '0.1.0'
|
3
3
|
end
|
data/lib/sinatra/application.rb
CHANGED
@@ -15,9 +15,11 @@ module Sinatra
|
|
15
15
|
get '/cometio/cometio.js' do
|
16
16
|
content_type 'application/javascript'
|
17
17
|
@js ||= (
|
18
|
-
js =
|
19
|
-
|
20
|
-
|
18
|
+
js = ''
|
19
|
+
Dir.glob(File.expand_path '../js/*.js', File.dirname(__FILE__)).each do |i|
|
20
|
+
File.open(i) do |f|
|
21
|
+
js += f.read
|
22
|
+
end
|
21
23
|
end
|
22
24
|
ERB.new(js).result(binding)
|
23
25
|
)
|
data/sample/Gemfile.lock
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
backports (2.
|
4
|
+
backports (2.8.2)
|
5
5
|
daemons (1.1.9)
|
6
|
-
event_emitter (0.
|
6
|
+
event_emitter (0.2.2)
|
7
7
|
eventmachine (1.0.0)
|
8
|
-
foreman (0.
|
8
|
+
foreman (0.61.0)
|
9
9
|
thor (>= 0.13.6)
|
10
10
|
haml (3.1.7)
|
11
|
-
json (1.7.
|
12
|
-
rack (1.
|
13
|
-
rack-protection (1.2
|
11
|
+
json (1.7.6)
|
12
|
+
rack (1.5.1)
|
13
|
+
rack-protection (1.3.2)
|
14
14
|
rack
|
15
15
|
rack-test (0.6.2)
|
16
16
|
rack (>= 1.0)
|
17
|
-
sass (3.2.
|
18
|
-
sinatra (1.3.
|
19
|
-
rack (~> 1.
|
20
|
-
rack-protection (~> 1.
|
17
|
+
sass (3.2.5)
|
18
|
+
sinatra (1.3.4)
|
19
|
+
rack (~> 1.4)
|
20
|
+
rack-protection (~> 1.3)
|
21
21
|
tilt (~> 1.3, >= 1.3.3)
|
22
22
|
sinatra-contrib (1.3.2)
|
23
23
|
backports (>= 2.0)
|
@@ -30,7 +30,7 @@ GEM
|
|
30
30
|
daemons (>= 1.0.9)
|
31
31
|
eventmachine (>= 0.12.6)
|
32
32
|
rack (>= 1.0.0)
|
33
|
-
thor (0.
|
33
|
+
thor (0.17.0)
|
34
34
|
tilt (1.3.3)
|
35
35
|
|
36
36
|
PLATFORMS
|
data/sinatra-cometio.gemspec
CHANGED
@@ -4,7 +4,7 @@ require 'sinatra-cometio/version'
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "sinatra-cometio"
|
7
|
-
gem.version =
|
7
|
+
gem.version = SinatraCometIO::VERSION
|
8
8
|
gem.authors = ["Sho Hashimoto"]
|
9
9
|
gem.email = ["hashimoto@shokai.org"]
|
10
10
|
gem.description = %q{Node.js like Comet I/O plugin for Sinatra.}
|
@@ -21,5 +21,5 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_dependency 'eventmachine', '>= 1.0.0'
|
22
22
|
gem.add_dependency 'sinatra-contrib', '>= 1.3.2'
|
23
23
|
gem.add_dependency 'json', '>= 1.7.0'
|
24
|
-
gem.add_dependency 'event_emitter', '>= 0.
|
24
|
+
gem.add_dependency 'event_emitter', '>= 0.2.0'
|
25
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-cometio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
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: 2013-
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
requirements:
|
99
99
|
- - ! '>='
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version: 0.
|
101
|
+
version: 0.2.0
|
102
102
|
type: :runtime
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -106,7 +106,7 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.
|
109
|
+
version: 0.2.0
|
110
110
|
description: Node.js like Comet I/O plugin for Sinatra.
|
111
111
|
email:
|
112
112
|
- hashimoto@shokai.org
|
@@ -118,11 +118,11 @@ files:
|
|
118
118
|
- Gemfile
|
119
119
|
- History.txt
|
120
120
|
- LICENSE.txt
|
121
|
-
- Manifest.txt
|
122
|
-
- PostInstall.txt
|
123
121
|
- README.md
|
124
122
|
- Rakefile
|
125
123
|
- lib/js/cometio.js
|
124
|
+
- lib/js/event_emitter.js
|
125
|
+
- lib/sinatra-cometio.rb
|
126
126
|
- lib/sinatra-cometio/version.rb
|
127
127
|
- lib/sinatra/application.rb
|
128
128
|
- lib/sinatra/cometio.rb
|
data/Manifest.txt
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
.gitignore
|
2
|
-
Gemfile
|
3
|
-
Gemfile.lock
|
4
|
-
History.txt
|
5
|
-
Manifest.txt
|
6
|
-
PostInstall.txt
|
7
|
-
README.rdoc
|
8
|
-
Rakefile
|
9
|
-
lib/js/cometio.js
|
10
|
-
lib/sinatra-cometio.rb
|
11
|
-
lib/sinatra/application.rb
|
12
|
-
lib/sinatra/cometio.rb
|
13
|
-
sample/.gitignore
|
14
|
-
sample/Gemfile
|
15
|
-
sample/Gemfile.lock
|
16
|
-
sample/Procfile
|
17
|
-
sample/README.md
|
18
|
-
sample/config.ru
|
19
|
-
sample/main.rb
|
20
|
-
sample/public/js/index.js
|
21
|
-
sample/views/index.haml
|
22
|
-
sample/views/main.scss
|
23
|
-
script/console
|
24
|
-
script/destroy
|
25
|
-
script/generate
|
26
|
-
test/test_helper.rb
|
27
|
-
test/test_sinatra-cometio.rb
|