web-repl 0.1 → 0.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.
- checksums.yaml +7 -0
- data/README.md +9 -8
- data/js/replConnection-0.1.min.js +1 -1
- data/js/replConnection.js +16 -4
- data/lib/web-repl.rb +1 -1
- metadata +22 -33
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c0998211915ac759b165b949d9feb445f3255996
|
4
|
+
data.tar.gz: 554e6169fce11bd5e0770923738bb90580e032ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a897a48b40350ee85b38336297376e8d1b5fe90e646a2eb860d492fe3e0363dc03cc2b5d0d7875a0c85f4c3827ccda4c990752cfd72eb9e151cf755d28d075dc
|
7
|
+
data.tar.gz: 92e2053ec83d835a829615535b81235eb42389034f757f54912f12e4b55997c4840ea41b032adb30a806824f0db53efed829d5082a04edcac481a8be858c5072
|
data/README.md
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# web-repl
|
2
2
|
|
3
|
-
|
3
|
+
A Javascript [REPL](http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop) that runs in Ruby. Evaluation is done by a web browser instance.
|
4
4
|
|
5
|
-
One use of this is to
|
5
|
+
One use of this is to replace the Chrome Developer Console remotely as such:
|
6
6
|
|
7
|
-
|
7
|
+

|
8
8
|
|
9
|
-
|
9
|
+
#### Background
|
10
10
|
|
11
|
-
|
11
|
+
I've been working on a toy project recently that requires browser content to be in fullscreen. This makes live coding using the regular Chrome JS console more or less impossible. I came up with web-repl as an alternative.
|
12
12
|
|
13
|
-
|
13
|
+
There are similar tools that run in nodejs and other languages but this is convenient for me because my project uses a Ruby backend anyway.
|
14
14
|
|
15
|
-
|
15
|
+
Server/client interaction uses JSON over Websocket. There's no extra attention to security here other than what is implicit in Websockets, so please use at your own discretion.
|
16
16
|
|
17
17
|
#### Usage
|
18
18
|
|
@@ -46,7 +46,7 @@ require "web-repl"
|
|
46
46
|
WebRepl.start(:host => "localhost", :port => 9007)
|
47
47
|
```
|
48
48
|
|
49
|
-
You can see an explanation of background usage here.
|
49
|
+
You can see an explanation of [background usage here](https://github.com/arirusso/web-repl/blob/master/examples/background.rb).
|
50
50
|
|
51
51
|
To use this as a script, run this from the command line. (The script should install with the gem)
|
52
52
|
|
@@ -64,3 +64,4 @@ or with Bundler
|
|
64
64
|
|
65
65
|
Licensed under Apache 2.0, See the file LICENSE
|
66
66
|
Copyright (c) 2014 [Ari Russo](http://arirusso.com)
|
67
|
+
|
@@ -1 +1 @@
|
|
1
|
-
function ReplConnection(e,t,n){if(n===null){n={}}this.debug=!!n.debug;this.reconnect=!!n.reconnect;this.retryTime=n.retryTime||1e3;this.onReceive=n.onReceive;this.host=e;this.port=t;this.active=false;this.socket;this.supported="WebSocket"in window;if(this.supported){console.log("REPL: socket ok")}else{console.log("REPL: socket not supported")}}ReplConnection.prototype.eval=function(statement){response={};try{response.value=eval(statement)}catch(err){response.error=err.message}return response};ReplConnection.prototype.initSocket=function(e){if(this.socket!==undefined&&this.socket!==null){this.socket.close()}var t="ws://"+this.host+":"+this.port+"/echo";this.socket=new WebSocket(t);e()};ReplConnection.prototype.handleSocketOpen=function(){this.active=true;console.log("REPL: socket ready")};ReplConnection.prototype.tryConnection=function(){console.log("REPL: waiting for connection");if(this.reconnect){var e=this;window.setTimeout(function(){e.start()},this.retryTime)}};ReplConnection.prototype.handleSocketClose=function(e){if(!this.active){this.tryConnection()}else{console.log("REPL: socket closed");this.active=false;if(this.reconnect){this.tryConnection()}}};ReplConnection.prototype.handleMessageReceived=function(e){if(this.debug){console.log("REPL: message received");console.log(e)}var t=JSON.parse(e.data);var n=t.timestamp;t.timestamp=new Date(n);if(this.onReceive!==undefined){this.onReceive(t)}var r=this.eval(t.statement);
|
1
|
+
function ReplConnection(e,t,n){if(n===null){n={}}this.debug=!!n.debug;this.reconnect=!!n.reconnect;this.retryTime=n.retryTime||1e3;this.onReceive=n.onReceive;this.host=e;this.port=t;this.active=false;this.socket;this.supported="WebSocket"in window;if(this.supported){console.log("REPL: socket ok")}else{console.log("REPL: socket not supported")}}ReplConnection.prototype.eval=function(statement){response={};try{response.value=eval(statement)}catch(err){response.error=err.message}return response};ReplConnection.prototype.initSocket=function(e){if(this.socket!==undefined&&this.socket!==null){this.socket.close()}var t="ws://"+this.host+":"+this.port+"/echo";this.socket=new WebSocket(t);e()};ReplConnection.prototype.handleSocketOpen=function(){this.active=true;console.log("REPL: socket ready")};ReplConnection.prototype.tryConnection=function(){console.log("REPL: waiting for connection");if(this.reconnect){var e=this;window.setTimeout(function(){e.start()},this.retryTime)}};ReplConnection.prototype.handleSocketClose=function(e){if(!this.active){this.tryConnection()}else{console.log("REPL: socket closed");this.active=false;if(this.reconnect){this.tryConnection()}}};ReplConnection.prototype.handleMessageReceived=function(e){if(this.debug){console.log("REPL: message received");console.log(e)}var t=JSON.parse(e.data);var n=t.timestamp;t.timestamp=new Date(n);if(this.onReceive!==undefined){this.onReceive(t)}var r=this.eval(t.statement);var i=this.prepareJSONResponse(r);if(this.debug){console.log("REPL: replying ");console.log(i)}this.socket.send(i)};ReplConnection.prototype.prepareJSONResponse=function(e){var t;try{e.timestamp=(new Date).getTime();t=JSON.stringify(e)}catch(n){e.value=null;e.error=n.message;t=this.prepareJSONResponse(e)}return t};ReplConnection.prototype.initEventHandling=function(){var e=this;this.socket.onopen=function(){e.handleSocketOpen()};this.socket.onclose=function(t){e.handleSocketClose(t)};this.socket.onmessage=function(t){e.handleMessageReceived(t)}};ReplConnection.prototype.start=function(e){if(this.supported){var t=this;this.initSocket(function(){t.initEventHandling();if(e!==undefined){e(t)}})}}
|
data/js/replConnection.js
CHANGED
@@ -84,17 +84,29 @@ ReplConnection.prototype.handleMessageReceived = function(event) {
|
|
84
84
|
if (this.onReceive !== undefined) {
|
85
85
|
this.onReceive(message); // fire the custom callback
|
86
86
|
}
|
87
|
-
// prepare the response
|
88
87
|
var response = this.eval(message.statement); // evaluate the statement
|
89
|
-
|
90
|
-
var json = JSON.stringify(response);
|
88
|
+
var json = this.prepareJSONResponse(response)
|
91
89
|
if (this.debug) {
|
92
90
|
console.log("REPL: replying ");
|
93
|
-
console.log(
|
91
|
+
console.log(json);
|
94
92
|
}
|
95
93
|
this.socket.send(json);
|
96
94
|
}
|
97
95
|
|
96
|
+
ReplConnection.prototype.prepareJSONResponse = function(response) {
|
97
|
+
// prepare the response
|
98
|
+
var json;
|
99
|
+
try {
|
100
|
+
response.timestamp = new Date().getTime(); // timestamp for the returned message
|
101
|
+
json = JSON.stringify(response);
|
102
|
+
} catch(err) {
|
103
|
+
response.value = null;
|
104
|
+
response.error = err.message;
|
105
|
+
json = this.prepareJSONResponse(response)
|
106
|
+
}
|
107
|
+
return json;
|
108
|
+
}
|
109
|
+
|
98
110
|
// Initialize the Websocket event handling actions
|
99
111
|
ReplConnection.prototype.initEventHandling = function() {
|
100
112
|
var connection = this;
|
data/lib/web-repl.rb
CHANGED
metadata
CHANGED
@@ -1,94 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web-repl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
5
|
-
prerelease:
|
4
|
+
version: '0.2'
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ari Russo
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-04 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: colorize
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: em-websocket
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: mocha
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rake
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - "~>"
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - "~>"
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: shoulda-context
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - "~>"
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - "~>"
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
description: Javascript/Web REPL in Ruby
|
@@ -99,41 +88,41 @@ executables:
|
|
99
88
|
extensions: []
|
100
89
|
extra_rdoc_files: []
|
101
90
|
files:
|
91
|
+
- LICENSE
|
92
|
+
- README.md
|
102
93
|
- bin/web-repl
|
103
94
|
- js/replConnection-0.1.min.js
|
104
95
|
- js/replConnection.js
|
96
|
+
- lib/web-repl.rb
|
105
97
|
- lib/web-repl/messager.rb
|
106
98
|
- lib/web-repl/patch.rb
|
107
99
|
- lib/web-repl/repl.rb
|
108
|
-
- lib/web-repl.rb
|
109
100
|
- test/helper.rb
|
110
101
|
- test/messager_test.rb
|
111
102
|
- test/repl_test.rb
|
112
|
-
- LICENSE
|
113
|
-
- README.md
|
114
103
|
homepage: http://github.com/arirusso/web-repl
|
115
|
-
licenses:
|
104
|
+
licenses:
|
105
|
+
- Apache License (2.0)
|
106
|
+
metadata: {}
|
116
107
|
post_install_message:
|
117
108
|
rdoc_options: []
|
118
109
|
require_paths:
|
119
110
|
- lib
|
120
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
112
|
requirements:
|
123
|
-
- -
|
113
|
+
- - ">="
|
124
114
|
- !ruby/object:Gem::Version
|
125
115
|
version: '0'
|
126
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
-
none: false
|
128
117
|
requirements:
|
129
|
-
- -
|
118
|
+
- - ">="
|
130
119
|
- !ruby/object:Gem::Version
|
131
120
|
version: 1.3.6
|
132
121
|
requirements: []
|
133
122
|
rubyforge_project: web-repl
|
134
|
-
rubygems_version:
|
123
|
+
rubygems_version: 2.2.2
|
135
124
|
signing_key:
|
136
|
-
specification_version:
|
125
|
+
specification_version: 4
|
137
126
|
summary: Javascript/Web REPL in Ruby
|
138
127
|
test_files:
|
139
128
|
- test/messager_test.rb
|