plezi 0.9.0 → 0.9.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1b45fb775eeba5ab996d2581da537e38640f7d4
4
- data.tar.gz: 1060b31518ce6e3ee36cfa315ce916f72e7ab1d2
3
+ metadata.gz: 17d2692e5f98a8cbbfc333e10d61614341562409
4
+ data.tar.gz: 40ef8b53dc05917ff5cc3dfa86bfbc2525f99e7b
5
5
  SHA512:
6
- metadata.gz: 030e93b8a30cc04c3ad35c3aae1303e335b5bd1558469e9673cc14e07417c17b43e0a271a4441bee64b53c6785804b2a9460cd391d3402c2cc12e0093fe0a626
7
- data.tar.gz: d663be79b8da32121b279848fc2cad6b5b66562ccbeedac9de25a41965bfa40380085a1b43af806f4f5e763a5e86eee7314e1f88fda8d5c43a2ba23d01c7fbc3
6
+ metadata.gz: 669e3220343b8f2a17a29d5854cc55bac0b49ea434dd0defa76b23bfeab180b2b0f506bf0f72f3d8c0043a678322f7f63d194966309552a3bcaf19cc97834c91
7
+ data.tar.gz: 728dbb5386131161aea6bb71d27c3a45ada870b9c5094be15b39c9303f388606ff1c9871f3ee0fa27459b50440ec4b898fbbcfe33607724b08a16c5d7d78c5f1
@@ -1,5 +1,14 @@
1
1
  #Change Log
2
2
 
3
+ ***
4
+
5
+ Change log v.0.9.1
6
+
7
+ **changed**: Template Gemfile now enforces the Plezi version. Also, the template's demo page now demonstrates WebSocket broadcasting.
8
+
9
+ Minor updates.
10
+
11
+
3
12
  ***
4
13
 
5
14
  Change log v.0.9.0
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"] ||= IO.read ::File.expand_path(File.join("..", "..", "resources" ,"Gemfile"), __FILE__)
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"
@@ -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.instance_eval { define_method name.to_s.to_sym, &block }
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 == 0140222) rescue true # if mode is read only, it's the same as closed.
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 == 0140222) rescue true # if mode is read only, it's the same as closed.
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
@@ -1,3 +1,3 @@
1
1
  module Plezi
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -1,10 +1,3 @@
1
- source "https://rubygems.org"
2
-
3
- ####################
4
- # core gems
5
-
6
- # include the basic plezi framework and server
7
- gem 'plezi'
8
1
 
9
2
  ####################
10
3
  # development gems
@@ -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 opening a WebSocket.
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
@@ -1,7 +1,8 @@
1
- <!DOCTYPE html><head><title>appname - Feed Me!</title>
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: 'Indie Flower', cursive;
24
+ font-family: 'Shadows Into Light', cursive;
24
25
  background-color: #1B2864;
25
26
  color: #99A3CE;
26
27
  text-align: center;
27
- border-bottom: 1px solid #424A70;
28
+ border-bottom: 4px solid #424A70;
28
29
  margin: 0 0 1em 0;
29
- padding: 0.5em 0;
30
+ padding: 0.4em 0;
30
31
  width: 100%;
31
-
32
32
  }
33
- h2, h3
33
+ h2
34
34
  {
35
35
  background-color: #44518E;
36
- color: #99A3CE;
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: 'Shadows Into Light', cursive;
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: #424A70;
59
+ color: #99A3CE;
46
60
  padding-right: 0.3em;
47
- margin-left: -1.5em;
61
+ margin-left: -0.5em;
48
62
  }
49
63
  h3:before {
50
64
  content: "|||||";
51
- color: #424A70;
65
+ color: #99A3CE;
52
66
  padding-right: 0.3em;
53
- margin-left: -2em;
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.0
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-06 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler