plezi 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/bin/plezi +4 -1
- data/lib/plezi/common/dsl.rb +1 -1
- data/lib/plezi/eventmachine/connection.rb +4 -4
- data/lib/plezi/eventmachine/ssl_connection.rb +1 -1
- data/lib/plezi/version.rb +1 -1
- data/resources/Gemfile +0 -7
- data/resources/controller.rb +7 -6
- data/resources/welcome_page.html +154 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17d2692e5f98a8cbbfc333e10d61614341562409
|
4
|
+
data.tar.gz: 40ef8b53dc05917ff5cc3dfa86bfbc2525f99e7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 669e3220343b8f2a17a29d5854cc55bac0b49ea434dd0defa76b23bfeab180b2b0f506bf0f72f3d8c0043a678322f7f63d194966309552a3bcaf19cc97834c91
|
7
|
+
data.tar.gz: 728dbb5386131161aea6bb71d27c3a45ada870b9c5094be15b39c9303f388606ff1c9871f3ee0fa27459b50440ec4b898fbbcfe33607724b08a16c5d7d78c5f1
|
data/CHANGELOG.md
CHANGED
data/bin/plezi
CHANGED
@@ -69,7 +69,9 @@ class AppTemplate
|
|
69
69
|
app_tree["rakefile"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"rakefile"), __FILE__)
|
70
70
|
app_tree["Procfile"] ||= ""
|
71
71
|
app_tree["Procfile"] << "\nweb: bundle exec ./#{ARGV[1]} -p $PORT\n"
|
72
|
-
app_tree["Gemfile"] ||=
|
72
|
+
app_tree["Gemfile"] ||= ''
|
73
|
+
app_tree["Gemfile"] << "source 'https://rubygems.org'\n\n####################\n# core gems\n\n# include the basic plezi framework and server\ngem 'plezi', '~> #{Plezi::VERSION}'\n"
|
74
|
+
app_tree["Gemfile"] << IO.read( ::File.expand_path(File.join("..", "..", "resources" ,"Gemfile"), __FILE__))
|
73
75
|
|
74
76
|
# set up config files
|
75
77
|
app_tree["config"] ||= {}
|
@@ -217,6 +219,7 @@ end
|
|
217
219
|
if ARGV[0] == 'new' || ARGV[0] == 'n' || ARGV[0] == "force"
|
218
220
|
#########
|
219
221
|
## set up building environment
|
222
|
+
require 'plezi/version'
|
220
223
|
BUILDING_PLEZI_TEMPLATE = true
|
221
224
|
ARGV[1] = ARGV[1].gsub /[^a-zA-Z0-9]/, '_'
|
222
225
|
if Dir.exists?(ARGV[1]) && ARGV[0] != "force"
|
data/lib/plezi/common/dsl.rb
CHANGED
@@ -180,7 +180,7 @@ end
|
|
180
180
|
# could also be used to define methods with special formatting, such as "humans.txt",
|
181
181
|
# until a more refined way to deal with formatting will be implemented.
|
182
182
|
def def_special_method name, obj=self, &block
|
183
|
-
obj.
|
183
|
+
obj.instance_exec { define_method name.to_s.to_sym, &block }
|
184
184
|
end
|
185
185
|
|
186
186
|
|
@@ -121,7 +121,7 @@ module Plezi
|
|
121
121
|
|
122
122
|
# returns true if the service is disconnected
|
123
123
|
def disconnected?
|
124
|
-
(@socket.closed? || socket.stat.mode
|
124
|
+
(@socket.closed? || socket.stat.mode != 0140666) rescue true # if mode is read only, it's the same as closed.
|
125
125
|
end
|
126
126
|
|
127
127
|
# returns true if the socket has content to be read.
|
@@ -178,9 +178,9 @@ module Plezi
|
|
178
178
|
def _send data
|
179
179
|
@active_time += 7200
|
180
180
|
len = data.bytesize
|
181
|
-
act = @socket.send data, 0
|
182
|
-
while len > act
|
183
|
-
act += @socket.send data.byteslice(act..-1) , 0
|
181
|
+
i = act = @socket.send data, 0
|
182
|
+
while len > act && i!=0
|
183
|
+
act += (i = @socket.send data.byteslice(act..-1) , 0)
|
184
184
|
end
|
185
185
|
touch
|
186
186
|
end
|
@@ -52,7 +52,7 @@ module Plezi
|
|
52
52
|
|
53
53
|
# returns true if the service is disconnected
|
54
54
|
def disconnected?
|
55
|
-
(@socket.closed? || @ssl_socket.closed? || @socket.stat.mode
|
55
|
+
(@socket.closed? || @ssl_socket.closed? || @socket.stat.mode != 0140666) rescue true # if mode is read only, it's the same as closed.
|
56
56
|
end
|
57
57
|
|
58
58
|
# identification markers
|
data/lib/plezi/version.rb
CHANGED
data/resources/Gemfile
CHANGED
data/resources/controller.rb
CHANGED
@@ -98,18 +98,18 @@ class SampleController
|
|
98
98
|
# called before the protocol is swithed from HTTP to WebSockets.
|
99
99
|
#
|
100
100
|
# this allows setting headers, cookies and other data (such as authentication)
|
101
|
-
# prior to
|
101
|
+
# prior to allowing a WebSocket to open.
|
102
102
|
#
|
103
103
|
# if the method returns false, the connection will be refused and the remaining routes will be attempted.
|
104
104
|
def pre_connect
|
105
|
-
false
|
105
|
+
# false
|
106
|
+
true
|
106
107
|
end
|
107
108
|
|
108
109
|
# called immediately after a WebSocket connection has been established.
|
109
|
-
# here we simply close the connection.
|
110
110
|
def on_connect
|
111
|
-
response.close
|
112
|
-
false
|
111
|
+
# response.close
|
112
|
+
# false
|
113
113
|
end
|
114
114
|
|
115
115
|
# called when new data is recieved
|
@@ -120,6 +120,7 @@ class SampleController
|
|
120
120
|
def on_message data
|
121
121
|
# broadcast sends an asynchronous message to all sibling instances, but not to self.
|
122
122
|
broadcast :_print_out, data
|
123
|
+
response << "You said: #{data}"
|
123
124
|
end
|
124
125
|
|
125
126
|
# called when a disconnect packet has been recieved or the connection has been cut
|
@@ -133,7 +134,7 @@ class SampleController
|
|
133
134
|
# BUT, broadcasted methods must be public (or the broadcast will quietly fail)... so we have to use
|
134
135
|
# the _underscore for this method.
|
135
136
|
def _print_out data
|
136
|
-
response << "Someone said #{data}"
|
137
|
+
response << "Someone said: #{data}"
|
137
138
|
end
|
138
139
|
|
139
140
|
end
|
data/resources/welcome_page.html
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
<!DOCTYPE html
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<head>
|
3
|
+
<title>appname - Feed Me!</title>
|
4
|
+
<meta content="width=device-width, initial-scale=1, maximum-scale=2.0, user-scalable=yes, minimal-ui=yes" name="viewport">
|
2
5
|
<link href='http://fonts.googleapis.com/css?family=Shadows+Into+Light|Architects+Daughter' rel='stylesheet' type='text/css'>
|
3
|
-
|
4
|
-
<link href="https://fonts.googleapis.com/css?family=Architects+Daughter" rel="stylesheet" type="text/css">
|
5
6
|
<style type="text/css">
|
6
7
|
/*
|
7
8
|
med-blue: #44518E
|
@@ -20,37 +21,50 @@ body, html
|
|
20
21
|
|
21
22
|
h1
|
22
23
|
{
|
23
|
-
font-family: '
|
24
|
+
font-family: 'Shadows Into Light', cursive;
|
24
25
|
background-color: #1B2864;
|
25
26
|
color: #99A3CE;
|
26
27
|
text-align: center;
|
27
|
-
border-bottom:
|
28
|
+
border-bottom: 4px solid #424A70;
|
28
29
|
margin: 0 0 1em 0;
|
29
|
-
padding: 0.
|
30
|
+
padding: 0.4em 0;
|
30
31
|
width: 100%;
|
31
|
-
|
32
32
|
}
|
33
|
-
h2
|
33
|
+
h2
|
34
34
|
{
|
35
35
|
background-color: #44518E;
|
36
|
-
color: #
|
36
|
+
color: #C6CCE7;
|
37
37
|
text-align: left;
|
38
38
|
margin: 0 0 1em 0;
|
39
39
|
padding: 0.5em 5%;
|
40
|
-
border-radius: 20px;
|
41
|
-
font-family: '
|
40
|
+
border-radius: 20px 20px 0 0;
|
41
|
+
font-family: 'Architects Daughter', cursive;
|
42
|
+
border-bottom: 3px solid #424A70;
|
43
|
+
font-size: 1.2em;
|
44
|
+
}
|
45
|
+
h3
|
46
|
+
{
|
47
|
+
font-family: 'Architects Daughter', cursive;
|
48
|
+
background-color: #44518E;
|
49
|
+
color: #C6CCE7;
|
50
|
+
text-align: left;
|
51
|
+
margin: 0 0 1em 0;
|
52
|
+
padding: 0.5em 5%;
|
53
|
+
border-radius: 1em 1em 0 0;
|
54
|
+
border-bottom: 2px solid #424A70;
|
55
|
+
font-size: 1.1em;
|
42
56
|
}
|
43
57
|
h2:before {
|
44
58
|
content: "|||";
|
45
|
-
color: #
|
59
|
+
color: #99A3CE;
|
46
60
|
padding-right: 0.3em;
|
47
|
-
margin-left: -
|
61
|
+
margin-left: -0.5em;
|
48
62
|
}
|
49
63
|
h3:before {
|
50
64
|
content: "|||||";
|
51
|
-
color: #
|
65
|
+
color: #99A3CE;
|
52
66
|
padding-right: 0.3em;
|
53
|
-
margin-left: -
|
67
|
+
margin-left: -1em;
|
54
68
|
}
|
55
69
|
h1 a, h2 a, h3 a
|
56
70
|
{
|
@@ -64,7 +78,7 @@ p
|
|
64
78
|
{
|
65
79
|
font-size: 1em;
|
66
80
|
padding: 0 1em;
|
67
|
-
margin: 0.5em 0;
|
81
|
+
margin: 0.5em 0;
|
68
82
|
}
|
69
83
|
a
|
70
84
|
{
|
@@ -96,8 +110,125 @@ pre
|
|
96
110
|
background-color: #444;
|
97
111
|
color: #ddd;
|
98
112
|
}
|
113
|
+
input[type=text]
|
114
|
+
{
|
115
|
+
width: 60%;
|
116
|
+
font-size: 1.1em;
|
117
|
+
display: inline-block;
|
118
|
+
background-color: #fff;
|
119
|
+
color: #424A70;
|
120
|
+
border-radius: 0.5em;
|
121
|
+
border: 1px solid #424A70;
|
122
|
+
outline: none;
|
123
|
+
box-sizing: border-box;
|
124
|
+
padding: 0 1em;
|
125
|
+
}
|
126
|
+
input[type=submit]
|
127
|
+
{
|
128
|
+
font-size: 1.1em;
|
129
|
+
color: #424A70;
|
130
|
+
border-radius: 0.5em;
|
131
|
+
box-sizing: border-box;
|
132
|
+
border: 1px solid #424A70;
|
133
|
+
background-color: #fff;
|
134
|
+
padding: 0 0.4em;
|
135
|
+
}
|
136
|
+
input[type=submit]:hover
|
137
|
+
{
|
138
|
+
background-color: #818ECE; color:#fff;
|
139
|
+
}
|
140
|
+
input[type=submit]:active
|
141
|
+
{
|
142
|
+
background-color: #1B2864; color:#fff;
|
143
|
+
}
|
144
|
+
|
145
|
+
#monitor
|
146
|
+
{
|
147
|
+
margin: 0 5%; padding: 0.5em 3em;
|
148
|
+
box-sizing: border-box;
|
149
|
+
width: 90%;
|
150
|
+
font-size: 1.1em;
|
151
|
+
display: inline-block;
|
152
|
+
background-color: #C6CCE7;
|
153
|
+
color: #424A70;
|
154
|
+
border-radius: 0.5em;
|
155
|
+
border: 1px solid #424A70;
|
156
|
+
}
|
157
|
+
#monitor p
|
158
|
+
{
|
159
|
+
text-align: center;
|
160
|
+
}
|
161
|
+
.system_message { color: #1B2864; font-style: italic;}
|
162
|
+
@media screen and (max-width: 680px)
|
163
|
+
{
|
164
|
+
input[type=submit], input[type=text] {
|
165
|
+
font-size: 1em;
|
166
|
+
}
|
167
|
+
input[type=text] { width: 100%;}
|
168
|
+
#monitor
|
169
|
+
{
|
170
|
+
margin: 0 3%; padding: 0.5em 1em;
|
171
|
+
}
|
172
|
+
ul {padding: 0 1em;}
|
173
|
+
}
|
99
174
|
|
100
175
|
</style>
|
176
|
+
<script type="text/javascript">
|
177
|
+
// Your websocket URI should be an absolute path. The following sets the base URI.
|
178
|
+
var ws_uri = 'ws://' + window.location.hostname + (window.location.port == '' ? '' : (':' + window.location.port) );
|
179
|
+
// remember to add the specific controller's path to your websocket URI.
|
180
|
+
ws_uri += "/";
|
181
|
+
// websocket variable.
|
182
|
+
var websocket = NaN
|
183
|
+
// count failed attempts
|
184
|
+
var websocket_fail = 0
|
185
|
+
|
186
|
+
function init_websocket()
|
187
|
+
{
|
188
|
+
websocket = new WebSocket(ws_uri);
|
189
|
+
websocket.onopen = function(e) {
|
190
|
+
//restart fail count
|
191
|
+
websocket_fail = 0
|
192
|
+
// what do you want to do now?
|
193
|
+
var msg = document.createElement("li");
|
194
|
+
msg.className = 'system_message'
|
195
|
+
msg.innerHTML = "Connected.";
|
196
|
+
document.getElementById("output").appendChild(msg);
|
197
|
+
};
|
198
|
+
|
199
|
+
websocket.onclose = function(e) {
|
200
|
+
// what do you want to do now?
|
201
|
+
if(websocket_fail == 0) {
|
202
|
+
var msg = document.createElement("li");
|
203
|
+
msg.className = 'system_message'
|
204
|
+
msg.innerHTML = "Disconnected.";
|
205
|
+
document.getElementById("output").appendChild(msg);
|
206
|
+
};
|
207
|
+
// you probably want to reopen the websocket if it closes (unless the issue repeats).
|
208
|
+
if(websocket_fail <= 5) {websocket_fail += 1; init_websocket(); };
|
209
|
+
};
|
210
|
+
websocket.onerror = function(e) {
|
211
|
+
// what do you want to do now?
|
212
|
+
};
|
213
|
+
websocket.onmessage = function(e) {
|
214
|
+
// what do you want to do now?
|
215
|
+
console.log(e.data);
|
216
|
+
var msg = document.createElement("li");
|
217
|
+
msg.innerHTML = e.data;
|
218
|
+
document.getElementById("output").appendChild(msg);
|
219
|
+
// to use JSON, use:
|
220
|
+
// msg = JSON.parse(e.data); // remember to use JSON also in your Plezi controller.
|
221
|
+
};
|
222
|
+
}
|
223
|
+
window.addEventListener("load", init_websocket, false);
|
224
|
+
function send_text()
|
225
|
+
{
|
226
|
+
var msg = document.getElementById("input").value;
|
227
|
+
document.getElementById("input").value = '';
|
228
|
+
websocket.send(msg);
|
229
|
+
return false;
|
230
|
+
}
|
231
|
+
</script>
|
101
232
|
</head>
|
102
233
|
<body>
|
103
234
|
<h1>Welcome to <a href="https://github.com/boazsegev/plezi">Plezi</a></h1>
|
@@ -125,5 +256,12 @@ pre
|
|
125
256
|
</li>
|
126
257
|
</ol>
|
127
258
|
<p class="bold">Good Luck!</p>
|
259
|
+
<h3> Did you try our websocket broadcast? </h3>
|
260
|
+
<p>Your appname app can send <span class="bold">WebSocket</span> broadcasts (and unicasts). Why not try them out? You can even try them across multiple windows.</p>
|
261
|
+
<form onsubmit='send_text(); return false;' id='monitor'>
|
262
|
+
<p><input type='text' id='input' placeholder='Your message' /> <input type='submit' value='Broadcast'/> </p>
|
263
|
+
<ul id='output'>
|
264
|
+
</ul>
|
265
|
+
</form>
|
128
266
|
</div>
|
129
267
|
</body>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plezi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boaz Segev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|