plezi 0.14.4 → 0.14.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/bin/ws_shootout +30 -0
- data/exe/plezi +108 -108
- data/lib/plezi.rb +18 -26
- data/lib/plezi/activation.rb +16 -16
- data/lib/plezi/api.rb +51 -50
- data/lib/plezi/controller/controller.rb +249 -229
- data/lib/plezi/controller/controller_class.rb +189 -174
- data/lib/plezi/controller/cookies.rb +49 -47
- data/lib/plezi/helpers.rb +35 -35
- data/lib/plezi/render/erb.rb +25 -26
- data/lib/plezi/render/has_cache.rb +31 -31
- data/lib/plezi/render/markdown.rb +53 -53
- data/lib/plezi/render/render.rb +36 -38
- data/lib/plezi/render/sass.rb +43 -44
- data/lib/plezi/render/slim.rb +25 -25
- data/lib/plezi/router/adclient.rb +14 -15
- data/lib/plezi/router/assets.rb +59 -61
- data/lib/plezi/router/errors.rb +22 -22
- data/lib/plezi/router/route.rb +98 -100
- data/lib/plezi/router/router.rb +120 -113
- data/lib/plezi/version.rb +1 -1
- data/lib/plezi/websockets/message_dispatch.rb +118 -80
- data/lib/plezi/websockets/redis.rb +42 -43
- data/plezi.gemspec +3 -3
- data/resources/client.js +229 -204
- data/resources/ctrlr.rb +26 -26
- data/resources/mini_app.rb +1 -1
- data/resources/simple-client.js +50 -43
- metadata +9 -8
data/resources/ctrlr.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
# Replace this sample with real code.
|
2
2
|
class RootController
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
# HTTP
|
4
|
+
def index
|
5
|
+
# any String returned will be appended to the response. We return a String.
|
6
|
+
render 'welcome'
|
7
|
+
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
# Websockets
|
10
|
+
def on_message(data)
|
11
|
+
data = ERB::Util.html_escape data
|
12
|
+
print data
|
13
|
+
broadcast :print, data
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
def on_open
|
17
|
+
print 'Welcome to appname!'
|
18
|
+
@handle = params['id'.freeze] || 'Somebody'
|
19
|
+
broadcast :print, "#{ERB::Util.html_escape @handle} joind us :-)"
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def on_close
|
23
|
+
broadcast :print, "#{@handle} left us :-("
|
24
|
+
end
|
25
25
|
|
26
|
-
|
26
|
+
protected
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
# write is inherites when a Websocket connection is opened.
|
29
|
+
#
|
30
|
+
# Inherited functions aren't exposed (for our security), so we need to wrap it.
|
31
|
+
def print(data)
|
32
|
+
write data
|
33
|
+
end
|
34
34
|
end
|
data/resources/mini_app.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
## Set environment, working directory, load gems and create logs
|
4
|
-
ENV['ENV'] ||= ENV['RACK_ENV'] # production ENV will render SASS as compressed.
|
4
|
+
ENV['ENV'] ||= ENV['RACK_ENV'] ||= ENV['RAILS_ENV'] # production ENV will render SASS as compressed.
|
5
5
|
## Using pathname extentions for setting public folder
|
6
6
|
require 'pathname'
|
7
7
|
## Set up root object, it might be used by the environment and\or the plezi extension gems.
|
data/resources/simple-client.js
CHANGED
@@ -5,54 +5,61 @@
|
|
5
5
|
|
6
6
|
// For an auto-dispatch, JSON implementation, consoder using the PleziClient.
|
7
7
|
|
8
|
-
// Your websocket URI should be an absolute path. The following sets the base
|
8
|
+
// Your websocket URI should be an absolute path. The following sets the base
|
9
|
+
// URI.
|
9
10
|
// remember to update to the specific controller's path to your websocket URI.
|
10
|
-
var ws_controller_path =
|
11
|
-
|
11
|
+
var ws_controller_path =
|
12
|
+
windselfow.location.pathname; // change to '/controller/path'
|
13
|
+
var ws_uri = (self.location.protocol.match(/https/) ? 'wss' : 'ws') + '://' +
|
14
|
+
self.document.location.host + ws_controller_path;
|
12
15
|
// websocket variable.
|
13
|
-
var websocket = NaN
|
16
|
+
var websocket = NaN;
|
14
17
|
// count failed attempts
|
15
|
-
var websocket_fail_count = 0
|
18
|
+
var websocket_fail_count = 0;
|
16
19
|
// to limit failed reconnection attempts, set this to a number.
|
17
|
-
var websocket_fail_limit = NaN
|
18
|
-
// to offer some space between reconnection attempts, set this interval in
|
19
|
-
|
20
|
+
var websocket_fail_limit = NaN;
|
21
|
+
// to offer some space between reconnection attempts, set this interval in
|
22
|
+
// miliseconds.
|
23
|
+
var websocket_reconnect_interval = 250;
|
20
24
|
|
21
|
-
function init_websocket()
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
function init_websocket() {
|
26
|
+
if (websocket && websocket.readyState == 1)
|
27
|
+
return true; // console.log('no need to renew socket connection');
|
28
|
+
websocket = new WebSocket(ws_uri);
|
29
|
+
websocket.onopen = function(e) {
|
30
|
+
// reset the count.
|
31
|
+
websocket_fail_count = 0;
|
32
|
+
// what do you want to do now?
|
33
|
+
};
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
35
|
+
websocket.onclose = function(e) {
|
36
|
+
// If the websocket repeatedly you probably want to report an error
|
37
|
+
if (!isNaN(websocket_fail_limit) &&
|
38
|
+
websocket_fail_count >= websocket_fail_limit) {
|
39
|
+
// What to do if we can't reconnect so many times?
|
40
|
+
return;
|
41
|
+
};
|
42
|
+
// you probably want to reopen the websocket if it closes.
|
43
|
+
if (isNaN(websocket_fail_limit) ||
|
44
|
+
(websocket_fail_count <= websocket_fail_limit)) {
|
45
|
+
// update the count
|
46
|
+
websocket_fail_count += 1;
|
47
|
+
// try to reconect
|
48
|
+
setTimeout(init_websocket, websocket_reconnect_interval);
|
49
|
+
};
|
50
|
+
};
|
51
|
+
websocket.onerror = function(e) {
|
52
|
+
// update the count.
|
53
|
+
websocket_fail_count += 1;
|
54
|
+
// what do you want to do now?
|
55
|
+
};
|
56
|
+
websocket.onmessage = function(e) {
|
57
|
+
// what do you want to do now?
|
58
|
+
console.log(e.data);
|
59
|
+
// to use JSON, use:
|
60
|
+
// msg = JSON.parse(e.data); // remember to use JSON also in your Plezi
|
61
|
+
// controller.
|
62
|
+
};
|
56
63
|
}
|
57
64
|
// setup the websocket connection once the page is done loading
|
58
|
-
self.addEventListener("load", init_websocket, false);
|
65
|
+
self.addEventListener("load", init_websocket, false);
|
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.14.
|
4
|
+
version: 0.14.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boaz Segev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iodine
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '0.2'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.2.
|
22
|
+
version: 0.2.14
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '0.2'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.2.
|
32
|
+
version: 0.2.14
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rack
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,28 +50,28 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '1.
|
53
|
+
version: '1.14'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '1.
|
60
|
+
version: '1.14'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rake
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
67
|
+
version: '11.0'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
74
|
+
version: '11.0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: minitest
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- bin/console
|
106
106
|
- bin/hello_world
|
107
107
|
- bin/setup
|
108
|
+
- bin/ws_shootout
|
108
109
|
- exe/plezi
|
109
110
|
- lib/plezi.rb
|
110
111
|
- lib/plezi/activation.rb
|