mad_chatter 0.3.1 → 0.3.2
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/.gitignore +2 -0
- data/.travis.yml +12 -0
- data/README.md +3 -5
- data/bin/mad_chatter +1 -1
- data/lib/mad_chatter.rb +22 -4
- data/lib/mad_chatter/config.rb +1 -6
- data/lib/mad_chatter/message.rb +5 -3
- data/lib/mad_chatter/message_listeners/channel_commands.rb +53 -0
- data/lib/mad_chatter/message_listeners/code.rb +0 -3
- data/lib/mad_chatter/message_listeners/markdown.rb +11 -5
- data/lib/mad_chatter/message_listeners/nick.rb +1 -1
- data/lib/mad_chatter/user.rb +1 -7
- data/lib/mad_chatter/version.rb +1 -1
- data/mad_chatter.gemspec +8 -7
- data/spec/mad_chatter_spec.rb +17 -0
- data/spec/message_listeners/{join_spec.rb → channel_commands_spec.rb} +17 -5
- data/spec/message_listeners/code_spec.rb +1 -1
- data/spec/message_listeners/markdown_spec.rb +12 -8
- data/spec/message_spec.rb +13 -3
- data/spec/spec_helper.rb +4 -7
- data/templates/web/css/mad_chatter.css +1 -1
- data/templates/web/index.html +35 -7
- data/templates/web/js/mad_chatter.js +33 -22
- data/templates/web/js/mad_chatter_config.js +1 -1
- metadata +28 -53
- data/Gemfile.lock +0 -53
- data/lib/mad_chatter/actions/base.rb +0 -26
- data/lib/mad_chatter/actions/dsl.rb +0 -38
- data/lib/mad_chatter/actions/join.rb +0 -23
- data/lib/mad_chatter/actions/rename.rb +0 -24
- data/lib/mad_chatter/connection.rb +0 -29
- data/lib/mad_chatter/markdown_renderer.rb +0 -16
- data/lib/mad_chatter/message_listeners/join.rb +0 -30
- data/lib/mad_chatter/servers/juggernaut.rb +0 -9
- data/lib/mad_chatter/servers/websocket_rack.rb +0 -9
- data/lib/mad_chatter/users.rb +0 -40
- data/spec/actions_spec.rb +0 -7
- data/spec/server_spec.rb +0 -43
- data/spec/users_spec.rb +0 -23
- data/templates/web/css/styles.css +0 -166
data/Gemfile.lock
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
mad_chatter (0.3.0)
|
5
|
-
daemons (= 1.1.4)
|
6
|
-
em-websocket
|
7
|
-
eventmachine
|
8
|
-
thor
|
9
|
-
|
10
|
-
GEM
|
11
|
-
remote: http://rubygems.org/
|
12
|
-
specs:
|
13
|
-
addressable (2.2.6)
|
14
|
-
daemons (1.1.4)
|
15
|
-
diff-lcs (1.1.3)
|
16
|
-
em-websocket (0.3.6)
|
17
|
-
addressable (>= 2.1.1)
|
18
|
-
eventmachine (>= 0.12.9)
|
19
|
-
eventmachine (0.12.10)
|
20
|
-
guard (0.8.8)
|
21
|
-
thor (~> 0.14.6)
|
22
|
-
guard-rspec (0.5.10)
|
23
|
-
guard (>= 0.8.4)
|
24
|
-
multi_json (1.0.4)
|
25
|
-
rb-fsevent (0.4.3.1)
|
26
|
-
rspec (2.7.0)
|
27
|
-
rspec-core (~> 2.7.0)
|
28
|
-
rspec-expectations (~> 2.7.0)
|
29
|
-
rspec-mocks (~> 2.7.0)
|
30
|
-
rspec-core (2.7.1)
|
31
|
-
rspec-expectations (2.7.0)
|
32
|
-
diff-lcs (~> 1.1.2)
|
33
|
-
rspec-mocks (2.7.0)
|
34
|
-
ruby-growl (3.0)
|
35
|
-
shoulda (2.11.3)
|
36
|
-
simplecov (0.5.4)
|
37
|
-
multi_json (~> 1.0.3)
|
38
|
-
simplecov-html (~> 0.5.3)
|
39
|
-
simplecov-html (0.5.3)
|
40
|
-
thor (0.14.6)
|
41
|
-
|
42
|
-
PLATFORMS
|
43
|
-
ruby
|
44
|
-
|
45
|
-
DEPENDENCIES
|
46
|
-
guard
|
47
|
-
guard-rspec
|
48
|
-
mad_chatter!
|
49
|
-
rb-fsevent
|
50
|
-
rspec
|
51
|
-
ruby-growl
|
52
|
-
shoulda
|
53
|
-
simplecov
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module MadChatter
|
2
|
-
module Actions
|
3
|
-
class Base
|
4
|
-
|
5
|
-
include MadChatter::Actions::Dsl
|
6
|
-
|
7
|
-
def initialize(regex = nil, block = nil)
|
8
|
-
@regex = regex
|
9
|
-
@block = block
|
10
|
-
end
|
11
|
-
|
12
|
-
def handle(message)
|
13
|
-
if message.original_text =~ @regex
|
14
|
-
args = @regex.match(message.original_text).captures
|
15
|
-
@block.call(args)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# used to register a class that extends MadChatter::Actions::Base
|
20
|
-
def self.inherited(extension_class)
|
21
|
-
MadChatter.message_listeners << extension_class.new
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module MadChatter
|
2
|
-
module Actions
|
3
|
-
module Dsl
|
4
|
-
|
5
|
-
# Used to define a simple extension
|
6
|
-
def on_message(regex, &block)
|
7
|
-
MadChatter.message_listeners << MadChatter::Actions::Base.new(regex, block)
|
8
|
-
end
|
9
|
-
|
10
|
-
# Helper methods
|
11
|
-
|
12
|
-
def stop_message_handling
|
13
|
-
raise "Don't call any more message listeners"
|
14
|
-
end
|
15
|
-
|
16
|
-
def send_json(json)
|
17
|
-
MadChatter::Server.send_json(json)
|
18
|
-
end
|
19
|
-
|
20
|
-
def send_message(text)
|
21
|
-
MadChatter::Server.send_message MadChatter::Message.new('message', text)
|
22
|
-
end
|
23
|
-
|
24
|
-
def send_status_message(text)
|
25
|
-
MadChatter::Server.send_message MadChatter::Message.new('status', text)
|
26
|
-
end
|
27
|
-
|
28
|
-
def send_users_list
|
29
|
-
MadChatter::Server.send_message MadChatter::Message.new('users', MadChatter::Users.current)
|
30
|
-
end
|
31
|
-
|
32
|
-
def send_action(action, *args)
|
33
|
-
MadChatter::Server.send_message MadChatter::Message.new('action', {function: action, args: args})
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module MadChatter
|
2
|
-
module Actions
|
3
|
-
class Join < MadChatter::Actions::Base
|
4
|
-
|
5
|
-
@@regex = /\/join (.+)/
|
6
|
-
|
7
|
-
def handle(message)
|
8
|
-
if message.filtered_text =~ @@regex
|
9
|
-
username = parse_username(message.filtered_text)
|
10
|
-
MadChatter::Users.update(message.token, username)
|
11
|
-
send_status_message "#{username} has joined the chatroom"
|
12
|
-
send_users_list
|
13
|
-
stop_message_handling
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def parse_username(text)
|
18
|
-
@@regex.match(text).captures[0]
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module MadChatter
|
2
|
-
module Actions
|
3
|
-
class Rename < MadChatter::Actions::Base
|
4
|
-
|
5
|
-
@@regex = /\/nick (.+)/
|
6
|
-
|
7
|
-
def handle(message)
|
8
|
-
if message.filtered_text =~ @@regex
|
9
|
-
old_username = message.username
|
10
|
-
username = parse_username(message.filtered_text)
|
11
|
-
MadChatter::Users.update(message.token, username)
|
12
|
-
send_status_message "#{old_username} is now known as #{username}"
|
13
|
-
send_users_list
|
14
|
-
stop_message_handling
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def parse_username(text)
|
19
|
-
@@regex.match(text).captures[0]
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module MadChatter
|
2
|
-
class Connection
|
3
|
-
|
4
|
-
def register_connection(&send_message)
|
5
|
-
subscriber_id = MadChatter::Server.main_channel.subscribe(send_message)
|
6
|
-
token = generate_token
|
7
|
-
send_message.call(MadChatter::Message.new('token', token).to_json)
|
8
|
-
@subscribers[subscriber_id] = token
|
9
|
-
MadChatter::MessageHistory.all.each do |json|
|
10
|
-
send_message.call(json)
|
11
|
-
end
|
12
|
-
subscriber_id
|
13
|
-
end
|
14
|
-
|
15
|
-
def generate_new_token
|
16
|
-
Digest::SHA1.hexdigest(Time.now.to_s)
|
17
|
-
end
|
18
|
-
|
19
|
-
def on_close
|
20
|
-
token = @subscribers.delete(id)
|
21
|
-
username = MadChatter::Users.find_username_by_token(token)
|
22
|
-
MadChatter::Server.main_channel.unsubscribe(id)
|
23
|
-
MadChatter::Users.remove(token)
|
24
|
-
MadChatter::Server.send_json(MadChatter::Message.new('status', "#{username} has left the chatroom").to_json)
|
25
|
-
MadChatter::Server.send_json(MadChatter::Message.new('users', MadChatter::Users.current).to_json)
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module MadChatter
|
2
|
-
class MarkdownRenderer < Redcarpet::Render::HTML
|
3
|
-
|
4
|
-
def link(link, title, alt_text)
|
5
|
-
"<a target=\"_blank\" href=\"#{link}\">#{alt_text}</a>"
|
6
|
-
end
|
7
|
-
|
8
|
-
def autolink(link, link_type)
|
9
|
-
"<a target=\"_blank\" href=\"#{link}\">#{link}</a>"
|
10
|
-
end
|
11
|
-
|
12
|
-
def header(text, header_level)
|
13
|
-
'#' + text
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module MadChatter
|
2
|
-
module MessageListeners
|
3
|
-
class Join
|
4
|
-
|
5
|
-
include MadChatter::Actions
|
6
|
-
|
7
|
-
@@regex = %r{^/join$}
|
8
|
-
|
9
|
-
def handle(message)
|
10
|
-
if message.text =~ @@regex
|
11
|
-
user = MadChatter.find_user_by_token(message.token)
|
12
|
-
|
13
|
-
unless user && message.channel
|
14
|
-
stop_message_handling # user should already exist, and channel id is required
|
15
|
-
end
|
16
|
-
|
17
|
-
channel = MadChatter.find_channel_by_id(message.channel)
|
18
|
-
|
19
|
-
unless channel
|
20
|
-
stop_message_handling # you cant join a channel that doesnt exist
|
21
|
-
end
|
22
|
-
|
23
|
-
channel.add_user(user)
|
24
|
-
stop_message_handling
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/mad_chatter/users.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module MadChatter
|
2
|
-
class Users
|
3
|
-
|
4
|
-
def initialize
|
5
|
-
@users = {}
|
6
|
-
end
|
7
|
-
|
8
|
-
def add(token, username = nil)
|
9
|
-
@users[token] = username
|
10
|
-
end
|
11
|
-
|
12
|
-
def update(token, username)
|
13
|
-
@users[token] = username
|
14
|
-
end
|
15
|
-
|
16
|
-
def remove(token)
|
17
|
-
@users.delete(token)
|
18
|
-
end
|
19
|
-
|
20
|
-
def find_username_by_token(token)
|
21
|
-
@users[token]
|
22
|
-
end
|
23
|
-
|
24
|
-
def current
|
25
|
-
@users.values
|
26
|
-
end
|
27
|
-
|
28
|
-
def token_exists?(token)
|
29
|
-
@users[token].exists?
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_json
|
33
|
-
JSON.generate({
|
34
|
-
type: 'users',
|
35
|
-
json: current,
|
36
|
-
})
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
data/spec/actions_spec.rb
DELETED
data/spec/server_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MadChatter::Server do
|
4
|
-
|
5
|
-
it 'should accept new connections' do
|
6
|
-
# todo
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should allow me to join a room that already exists' do
|
10
|
-
# todo
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should not allow me to join a room that doesnt exist, unless I create it' do
|
14
|
-
# todo
|
15
|
-
end
|
16
|
-
|
17
|
-
# context '#send_message' do
|
18
|
-
# it 'should add regular messages to the message history' do
|
19
|
-
# MadChatter::MessageHistory.all.length.should == 0
|
20
|
-
# message = MadChatter::Message.new('message', 'regular message');
|
21
|
-
# MadChatter::Server.send_message message
|
22
|
-
# MadChatter::MessageHistory.all.length.should == 1
|
23
|
-
# end
|
24
|
-
# it 'should add status messages to the message history' do
|
25
|
-
# MadChatter::MessageHistory.all.length.should == 0
|
26
|
-
# message = MadChatter::Message.new('status', 'status message');
|
27
|
-
# MadChatter::Server.send_message message
|
28
|
-
# MadChatter::MessageHistory.all.length.should == 1
|
29
|
-
# end
|
30
|
-
# it 'should not add action messages to the message history' do
|
31
|
-
# MadChatter::MessageHistory.all.length.should == 0
|
32
|
-
# message = MadChatter::Message.new('action', 'action message');
|
33
|
-
# MadChatter::Server.send_message message
|
34
|
-
# MadChatter::MessageHistory.all.length.should == 0
|
35
|
-
# end
|
36
|
-
# it 'should not add user list messages to the message history' do
|
37
|
-
# MadChatter::MessageHistory.all.length.should == 0
|
38
|
-
# message = MadChatter::Message.new('users', 'list of users');
|
39
|
-
# MadChatter::Server.send_message message
|
40
|
-
# MadChatter::MessageHistory.all.length.should == 0
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
end
|
data/spec/users_spec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# require 'spec_helper'
|
2
|
-
#
|
3
|
-
# describe MadChatter::Users do
|
4
|
-
#
|
5
|
-
# it 'should have a well-known interface' do
|
6
|
-
# [:users, :add, :update, :remove, :find_username_by_token, :current, :token_exists?].each do |m|
|
7
|
-
# MadChatter::Users.should respond_to(m)
|
8
|
-
# end
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# it 'should store users and their usernames' do
|
12
|
-
# MadChatter::Users.add 'token1', 'username1'
|
13
|
-
# MadChatter::Users.add 'token2', 'username2'
|
14
|
-
# MadChatter::Users.current.should == ['username1', 'username2']
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# it 'should encode into JSON correctly' do
|
18
|
-
# MadChatter::Users.add 'token1', 'username1'
|
19
|
-
# MadChatter::Users.add 'token2', 'username2'
|
20
|
-
# MadChatter::Users.to_json.should == '{"type":"users","json":["username1","username2"]}'
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# end
|
@@ -1,166 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* CSS Reset Styles
|
3
|
-
* http://meyerweb.com/eric/tools/css/reset/
|
4
|
-
* v2.0 | 20110126
|
5
|
-
* License: none (public domain)
|
6
|
-
*/
|
7
|
-
html, body, div, span, applet, object, iframe,
|
8
|
-
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
9
|
-
a, abbr, acronym, address, big, cite, code,
|
10
|
-
del, dfn, em, img, ins, kbd, q, s, samp,
|
11
|
-
small, strike, strong, sub, sup, tt, var,
|
12
|
-
b, u, i, center,
|
13
|
-
dl, dt, dd, ol, ul, li,
|
14
|
-
fieldset, form, label, legend,
|
15
|
-
table, caption, tbody, tfoot, thead, tr, th, td,
|
16
|
-
article, aside, canvas, details, embed,
|
17
|
-
figure, figcaption, footer, header, hgroup,
|
18
|
-
menu, nav, output, ruby, section, summary,
|
19
|
-
time, mark, audio, video {
|
20
|
-
margin: 0;
|
21
|
-
padding: 0;
|
22
|
-
border: 0;
|
23
|
-
font-size: 100%;
|
24
|
-
font: inherit;
|
25
|
-
vertical-align: baseline;
|
26
|
-
}
|
27
|
-
/* HTML5 display-role reset for older browsers */
|
28
|
-
article, aside, details, figcaption, figure,
|
29
|
-
footer, header, hgroup, menu, nav, section {
|
30
|
-
display: block;
|
31
|
-
}
|
32
|
-
body {
|
33
|
-
line-height: 1;
|
34
|
-
}
|
35
|
-
ol, ul {
|
36
|
-
list-style: none;
|
37
|
-
}
|
38
|
-
blockquote, q {
|
39
|
-
quotes: none;
|
40
|
-
}
|
41
|
-
blockquote:before, blockquote:after,
|
42
|
-
q:before, q:after {
|
43
|
-
content: '';
|
44
|
-
content: none;
|
45
|
-
}
|
46
|
-
table {
|
47
|
-
border-collapse: collapse;
|
48
|
-
border-spacing: 0;
|
49
|
-
}
|
50
|
-
|
51
|
-
|
52
|
-
/***************** Mad Chatter Styles *****************/
|
53
|
-
|
54
|
-
#login_screen header {
|
55
|
-
padding: 150px 0 20px;
|
56
|
-
color: #fff;
|
57
|
-
background-color: #000;
|
58
|
-
text-align: center;
|
59
|
-
font: 25px Verdana, Geneva, Arial, Helvetica, sans-serif;
|
60
|
-
}
|
61
|
-
|
62
|
-
#login_screen #pick_a_username {
|
63
|
-
text-align: center;
|
64
|
-
background: #fff;
|
65
|
-
padding: 5px 10px 10px;
|
66
|
-
font: 18px Verdana, Geneva, Arial, Helvetica, sans-serif;
|
67
|
-
}
|
68
|
-
|
69
|
-
#login_screen #pick_a_username p {
|
70
|
-
margin: 10px;
|
71
|
-
}
|
72
|
-
#login_screen #pick_a_username input, #login_screen #pick_a_username button {
|
73
|
-
font: 14px Verdana, Geneva, Arial, Helvetica, sans-serif;
|
74
|
-
padding: 5px;
|
75
|
-
}
|
76
|
-
|
77
|
-
#chat_wrapper {
|
78
|
-
margin:0;
|
79
|
-
padding:0 0 100px 200px;
|
80
|
-
font: 12px Verdana, Geneva, Arial, Helvetica, sans-serif;
|
81
|
-
}
|
82
|
-
|
83
|
-
#chat_wrapper ul#tabs {
|
84
|
-
float: left;
|
85
|
-
background: green;
|
86
|
-
}
|
87
|
-
|
88
|
-
#chat_wrapper .sidebar{
|
89
|
-
position:absolute;
|
90
|
-
top:0;
|
91
|
-
left:0;
|
92
|
-
width:200px;
|
93
|
-
height:100%;
|
94
|
-
color: #fff;
|
95
|
-
background-color: #000;
|
96
|
-
padding: 20px 5px 0 15px;
|
97
|
-
}
|
98
|
-
|
99
|
-
#chat_wrapper .sidebar h2 {
|
100
|
-
font: 14px Verdana, Geneva, Arial, Helvetica, sans-serif;
|
101
|
-
margin-bottom: 10px;
|
102
|
-
}
|
103
|
-
|
104
|
-
#chat_wrapper .room ul.users li {
|
105
|
-
margin-left: 1em;
|
106
|
-
}
|
107
|
-
|
108
|
-
#chat_wrapper .room .messages {
|
109
|
-
padding: 20px 10px 0px 40px;
|
110
|
-
}
|
111
|
-
|
112
|
-
#chat_wrapper .room .messages p {
|
113
|
-
padding: 0.25em;
|
114
|
-
clear: both;
|
115
|
-
}
|
116
|
-
|
117
|
-
#chat_wrapper .room .messages strong { font-weight: bold; }
|
118
|
-
#chat_wrapper .room .messages em { font-style: italic; }
|
119
|
-
|
120
|
-
#chat_wrapper .room .messages p.message .username {
|
121
|
-
font-weight: bold;
|
122
|
-
}
|
123
|
-
|
124
|
-
#chat_wrapper .room .messages p.message time,
|
125
|
-
#chat_wrapper .room .messages p.status time {
|
126
|
-
float: right;
|
127
|
-
color: #999;
|
128
|
-
}
|
129
|
-
|
130
|
-
#chat_wrapper .room .messages p.status {
|
131
|
-
text-align: center;
|
132
|
-
color: #999;
|
133
|
-
}
|
134
|
-
|
135
|
-
#chat_wrapper .room .new_message {
|
136
|
-
bottom: 0;
|
137
|
-
left: 220px;
|
138
|
-
width: 100%;
|
139
|
-
background-color: #eee;
|
140
|
-
padding: 0 10px;
|
141
|
-
}
|
142
|
-
|
143
|
-
#chat_wrapper .room .new_message input {
|
144
|
-
width: 15%;
|
145
|
-
padding: 5px;
|
146
|
-
}
|
147
|
-
|
148
|
-
@media screen{
|
149
|
-
#chat_wrapper .sidebar { position:fixed; }
|
150
|
-
#chat_wrapper .room .new_message { position:fixed; }
|
151
|
-
}
|
152
|
-
|
153
|
-
* html #chat_wrapper {
|
154
|
-
overflow:hidden;
|
155
|
-
}
|
156
|
-
|
157
|
-
* html #chat_wrapper .room .messages {
|
158
|
-
height:100%;
|
159
|
-
overflow:auto;
|
160
|
-
}
|
161
|
-
|
162
|
-
pre, code {
|
163
|
-
font: 12px 'Bitstream Vera Sans Mono','Courier',monospace;
|
164
|
-
padding: 2px !important;
|
165
|
-
background-color: #EEE !important;
|
166
|
-
}
|