webconsole 0.0.4 → 0.1.0
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 +4 -4
- data/lib/applescript/load_html.scpt +0 -0
- data/lib/applescript/load_html_with_base_url.scpt +0 -0
- data/lib/webconsole.rb +5 -4
- data/lib/webconsole/dependencies.rb +41 -0
- data/lib/webconsole/dependencies/css/style.css +15 -0
- data/lib/webconsole/dependencies/js/wcdependencies.js +10 -0
- data/lib/webconsole/dependencies/lib/controller.rb +36 -0
- data/lib/webconsole/dependencies/lib/model.rb +10 -0
- data/lib/webconsole/dependencies/lib/tester.rb +19 -0
- data/lib/webconsole/dependencies/lib/view.rb +19 -0
- data/lib/webconsole/dependencies/views/view.html.erb +25 -0
- data/lib/webconsole/extension_constants.rb +1 -0
- data/lib/webconsole/{constants.rb → lib/constants.rb} +1 -1
- data/lib/webconsole/lib/controller.rb +5 -0
- data/lib/webconsole/{module.rb → lib/module.rb} +0 -0
- data/lib/webconsole/lib/view.rb +34 -0
- data/lib/webconsole/lib/view/erb.rb +17 -0
- data/lib/webconsole/lib/view/javascript.rb +78 -0
- data/lib/webconsole/lib/view/resources.rb +48 -0
- data/lib/webconsole/{window_manager.rb → lib/window.rb} +7 -2
- data/lib/webconsole/repl.rb +58 -0
- data/lib/webconsole/repl/css/style.css +20 -0
- data/lib/webconsole/repl/js/wcrepl.js +17 -0
- data/lib/webconsole/repl/lib/input_controller.rb +17 -0
- data/lib/webconsole/repl/lib/output_controller.rb +18 -0
- data/lib/webconsole/repl/lib/view.rb +68 -0
- data/lib/webconsole/repl/view/view.html.erb +12 -0
- metadata +30 -9
- data/lib/webconsole/controller.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70395a2c52eb177d5822716aac4e2abfeec7e95f
|
4
|
+
data.tar.gz: aec4858a911a98087d24565ae96a0eb737e3589d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35ae7c659a3f1eba971b886723cc4c470311111f259660e539ff26b2872919f3c1908688e78e7029e47a11c8ff3615d0b705e04f87a11ec62c20025234d3b266
|
7
|
+
data.tar.gz: 5ca14d43ea863d47b7e02abc0e016a8e158c45d938a95c3ce3ee09c7c9ff209a4e6675a754df85be6634e630433b0f06aa38485e11e096c719a65f00f50adf71
|
Binary file
|
Binary file
|
data/lib/webconsole.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module WebConsole
|
2
|
-
require_relative "webconsole/constants"
|
3
|
-
require_relative "webconsole/
|
4
|
-
require_relative "webconsole/controller"
|
5
|
-
require_relative "webconsole/
|
2
|
+
require_relative "webconsole/lib/constants"
|
3
|
+
require_relative "webconsole/lib/window"
|
4
|
+
require_relative "webconsole/lib/controller"
|
5
|
+
require_relative "webconsole/lib/view"
|
6
|
+
require_relative "webconsole/lib/module"
|
6
7
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative 'extension_constants'
|
2
|
+
require WEBCONSOLE_FILE
|
3
|
+
|
4
|
+
module WebConsole::Dependencies
|
5
|
+
class Checker
|
6
|
+
require_relative 'dependencies/lib/model'
|
7
|
+
require_relative 'dependencies/lib/controller'
|
8
|
+
|
9
|
+
def check_dependencies(dependencies)
|
10
|
+
passed = true
|
11
|
+
dependencies.each { |dependency|
|
12
|
+
dependency_passed = check(dependency)
|
13
|
+
if !dependency_passed
|
14
|
+
passed = false
|
15
|
+
end
|
16
|
+
}
|
17
|
+
return passed
|
18
|
+
end
|
19
|
+
|
20
|
+
def check(dependency)
|
21
|
+
name = dependency.name
|
22
|
+
type = dependency.type
|
23
|
+
passed = Tester::check(name, type)
|
24
|
+
if !passed
|
25
|
+
controller.missing_dependency(dependency)
|
26
|
+
end
|
27
|
+
return passed
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def controller
|
33
|
+
if !@controller
|
34
|
+
@controller = Controller.new
|
35
|
+
end
|
36
|
+
return @controller
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
body, h5 {
|
2
|
+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
3
|
+
font-size: 13px;
|
4
|
+
}
|
5
|
+
h5 {
|
6
|
+
font-weight: normal;
|
7
|
+
color: red;
|
8
|
+
}
|
9
|
+
blockquote {
|
10
|
+
margin-left: 2em;
|
11
|
+
}
|
12
|
+
code {
|
13
|
+
background-color: #DBE2EC;
|
14
|
+
font-family: "Menlo", monospace;
|
15
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
function addMissingDependency(name, type, installationInstructions) {
|
2
|
+
var source = $("#dependency-template").html();
|
3
|
+
var template = Handlebars.compile(source);
|
4
|
+
var data = {
|
5
|
+
name: name,
|
6
|
+
type: type,
|
7
|
+
installationInstructions: installationInstructions
|
8
|
+
};
|
9
|
+
$(template(data)).appendTo("body");
|
10
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'tester'
|
2
|
+
require_relative 'model'
|
3
|
+
require_relative 'view'
|
4
|
+
|
5
|
+
module WebConsole::Dependencies
|
6
|
+
|
7
|
+
class Controller < WebConsole::Controller
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@view = View.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def missing_dependency(dependency)
|
14
|
+
name = dependency.name
|
15
|
+
type = self.class.string_for_type(dependency.type)
|
16
|
+
options = dependency.options
|
17
|
+
|
18
|
+
if options.has_key?(:installation_instructions)
|
19
|
+
installation_instructions = options[:installation_instructions]
|
20
|
+
end
|
21
|
+
|
22
|
+
@view.add_missing_dependency(name, type, installation_instructions)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def self.string_for_type(type)
|
28
|
+
case type
|
29
|
+
when :shell_command
|
30
|
+
return "shell command"
|
31
|
+
end
|
32
|
+
return nil
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module WebConsole::Dependencies
|
2
|
+
module Tester
|
3
|
+
def self.check(name, type)
|
4
|
+
case type
|
5
|
+
when :shell_command
|
6
|
+
return check_shell_command(name)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
require 'shellwords'
|
13
|
+
def self.check_shell_command(name)
|
14
|
+
command = "type -a #{Shellwords.escape(name)} > /dev/null 2>&1"
|
15
|
+
return system(command)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module WebConsole::Dependencies
|
2
|
+
|
3
|
+
class View < WebConsole::View
|
4
|
+
BASE_DIRECTORY = File.join(File.dirname(__FILE__), '..')
|
5
|
+
VIEWS_DIRECTORY = File.join(BASE_DIRECTORY, "views")
|
6
|
+
VIEW_TEMPLATE = File.join(VIEWS_DIRECTORY, 'view.html.erb')
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
self.base_url_path = File.expand_path(BASE_DIRECTORY)
|
11
|
+
load_erb_from_path(VIEW_TEMPLATE)
|
12
|
+
end
|
13
|
+
|
14
|
+
ADD_MISSING_DEPENDENCY_FUNCTION = "addMissingDependency"
|
15
|
+
def add_missing_dependency(name, type, installation_instructions = nil)
|
16
|
+
self.do_javascript_function(ADD_MISSING_DEPENDENCY_FUNCTION, [name, type, installation_instructions])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8" />
|
5
|
+
<title><%= title %></title>
|
6
|
+
<%= shared_stylesheet_link_tag "raster" %>
|
7
|
+
<link rel="stylesheet" href="css/style.css" />
|
8
|
+
<script id="dependency-template" type="text/x-handlebars-template">
|
9
|
+
<section>
|
10
|
+
<header>
|
11
|
+
<h5>Dependency <span class="type">{{type}}</span> <code class="name">{{name}}</code> not found.</h5>
|
12
|
+
</header>
|
13
|
+
{{#if installationInstructions}}
|
14
|
+
<p><blockquote class="installation">To install <code>{{name}}</code>: {{{installationInstructions}}}</blockquote></p>
|
15
|
+
{{/if}}
|
16
|
+
</section>
|
17
|
+
</script>
|
18
|
+
<%= shared_javascript_include_tag "handlebars" %>
|
19
|
+
<%= shared_javascript_include_tag "zepto" %>
|
20
|
+
<script type="text/javascript" src="js/wcdependencies.js"></script>
|
21
|
+
</head>
|
22
|
+
<body>
|
23
|
+
|
24
|
+
</body>
|
25
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
WEBCONSOLE_FILE = File.join(File.dirname(__FILE__), "../webconsole")
|
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative "view/javascript"
|
2
|
+
require_relative "view/erb"
|
3
|
+
require_relative "view/resources"
|
4
|
+
|
5
|
+
module WebConsole
|
6
|
+
class View
|
7
|
+
|
8
|
+
attr_reader :window
|
9
|
+
def initialize
|
10
|
+
@window = WebConsole::Window.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def base_url=(value)
|
14
|
+
@window.base_url = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def base_url_path=(value)
|
18
|
+
@window.base_url_path = value
|
19
|
+
end
|
20
|
+
|
21
|
+
def load_html(html)
|
22
|
+
@window.load_html(html)
|
23
|
+
end
|
24
|
+
|
25
|
+
def do_javascript(javascript)
|
26
|
+
return @window.do_javascript(javascript)
|
27
|
+
end
|
28
|
+
|
29
|
+
def close
|
30
|
+
@window.close
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module WebConsole
|
2
|
+
class View
|
3
|
+
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
def load_erb_from_path(path)
|
7
|
+
erb = File.new(path).read
|
8
|
+
load_erb(erb)
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_erb(erb)
|
12
|
+
template = ERB.new(erb, nil, '-')
|
13
|
+
html = template.result(binding)
|
14
|
+
load_html(html)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module WebConsole
|
2
|
+
class View
|
3
|
+
|
4
|
+
def do_javascript_function(function, arguments = nil)
|
5
|
+
javascript = self.class.javascript_function(function, arguments)
|
6
|
+
result = do_javascript(javascript)
|
7
|
+
result.chomp!
|
8
|
+
|
9
|
+
if result.is_integer?
|
10
|
+
return result.to_i
|
11
|
+
end
|
12
|
+
|
13
|
+
if result.is_float?
|
14
|
+
return result.to_f
|
15
|
+
end
|
16
|
+
|
17
|
+
return result
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.javascript_function(function, arguments = nil)
|
21
|
+
function = function.dup
|
22
|
+
function << '('
|
23
|
+
|
24
|
+
if arguments
|
25
|
+
arguments.each { |argument|
|
26
|
+
if argument
|
27
|
+
function << argument.javascript_argument
|
28
|
+
else
|
29
|
+
function << "null"
|
30
|
+
end
|
31
|
+
function << ', '
|
32
|
+
}
|
33
|
+
function = function[0...-2]
|
34
|
+
end
|
35
|
+
|
36
|
+
function << ');'
|
37
|
+
|
38
|
+
return function
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
class ::String
|
44
|
+
def javascript_argument
|
45
|
+
return "'#{self.javascript_escape}'"
|
46
|
+
end
|
47
|
+
|
48
|
+
def javascript_escape
|
49
|
+
self.gsub('\\', "\\\\\\\\").gsub("\n", "\\\\n").gsub("'", "\\\\'")
|
50
|
+
end
|
51
|
+
|
52
|
+
def javascript_escape!
|
53
|
+
replace(self.javascript_escape)
|
54
|
+
end
|
55
|
+
|
56
|
+
def is_float?
|
57
|
+
!!Float(self) rescue false
|
58
|
+
end
|
59
|
+
|
60
|
+
def is_integer?
|
61
|
+
self.to_i.to_s == self
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class ::Float
|
66
|
+
def javascript_argument
|
67
|
+
return self.to_s
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class ::Integer
|
72
|
+
def javascript_argument
|
73
|
+
return self.to_s
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module WebConsole
|
2
|
+
class View
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
require_relative "../constants"
|
6
|
+
require_relative "../module"
|
7
|
+
|
8
|
+
attr_accessor :title
|
9
|
+
|
10
|
+
CSS_EXTENSION = ".css"
|
11
|
+
CSS_PATH_COMPONENT = "css/"
|
12
|
+
def shared_stylesheet_link_tag(resource)
|
13
|
+
uri = URI.join(shared_resources_url, CSS_PATH_COMPONENT, resource + CSS_EXTENSION)
|
14
|
+
return stylesheet_link_tag(uri.to_s)
|
15
|
+
end
|
16
|
+
|
17
|
+
def stylesheet_link_tag(url)
|
18
|
+
return "<link rel=\"stylesheet\" href=\"#{url}\" />"
|
19
|
+
end
|
20
|
+
|
21
|
+
JS_EXTENSION = ".js"
|
22
|
+
JS_PATH_COMPONENT = "js/"
|
23
|
+
def shared_javascript_include_tag(resource)
|
24
|
+
uri = URI.join(shared_resources_url, JS_PATH_COMPONENT, resource + JS_EXTENSION)
|
25
|
+
return javascript_include_tag(uri.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def javascript_include_tag(url)
|
29
|
+
return "<script type=\"text/javascript\" src=\"#{url}\"></script>"
|
30
|
+
end
|
31
|
+
|
32
|
+
def title
|
33
|
+
if !@title && ENV.has_key?(PLUGIN_NAME_KEY)
|
34
|
+
@title = ENV[PLUGIN_NAME_KEY]
|
35
|
+
end
|
36
|
+
return @title
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def shared_resources_url
|
42
|
+
if !@shared_resources_url
|
43
|
+
@shared_resources_url = ENV.has_key?(SHARED_RESOURCES_URL_KEY)? ENV[SHARED_RESOURCES_URL_KEY] : WebConsole::shared_resources_url
|
44
|
+
end
|
45
|
+
return @shared_resources_url
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module WebConsole
|
2
|
-
class
|
2
|
+
class Window
|
3
3
|
require_relative "constants"
|
4
4
|
|
5
5
|
attr_writer :base_url
|
@@ -13,10 +13,14 @@ module WebConsole
|
|
13
13
|
end
|
14
14
|
|
15
15
|
LOADHTML_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "load_html.scpt")
|
16
|
+
LOADHTMLWITHBASEURL_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "load_html_with_base_url.scpt")
|
16
17
|
def load_html(html)
|
17
18
|
arguments = [html]
|
18
19
|
|
20
|
+
script = LOADHTML_SCRIPT
|
21
|
+
|
19
22
|
if @base_url
|
23
|
+
script = LOADHTMLWITHBASEURL_SCRIPT
|
20
24
|
arguments.push(@base_url)
|
21
25
|
end
|
22
26
|
|
@@ -24,7 +28,7 @@ module WebConsole
|
|
24
28
|
arguments.push(window_id)
|
25
29
|
end
|
26
30
|
|
27
|
-
result = WebConsole::run_applescript(
|
31
|
+
result = WebConsole::run_applescript(script, arguments)
|
28
32
|
if !window_id
|
29
33
|
# This allows a window manager created without a window_id and then be assigned the window_id when load_html is called.
|
30
34
|
@window_id = self.class.window_id_from_result(result)
|
@@ -53,5 +57,6 @@ module WebConsole
|
|
53
57
|
def self.window_id_from_result(result)
|
54
58
|
return result.split.last.to_i
|
55
59
|
end
|
60
|
+
|
56
61
|
end
|
57
62
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative 'extension_constants'
|
2
|
+
require WEBCONSOLE_FILE
|
3
|
+
|
4
|
+
module WebConsole::REPL
|
5
|
+
require_relative "repl/lib/input_controller"
|
6
|
+
require_relative "repl/lib/output_controller"
|
7
|
+
require_relative "repl/lib/view"
|
8
|
+
|
9
|
+
class Wrapper
|
10
|
+
require 'pty'
|
11
|
+
def initialize(command)
|
12
|
+
|
13
|
+
PTY.spawn(command) do |output, input, pid|
|
14
|
+
Thread.new do
|
15
|
+
output.each { |line|
|
16
|
+
output_controller.parse_output(line)
|
17
|
+
}
|
18
|
+
end
|
19
|
+
@input = input
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_input(input)
|
24
|
+
input_controller.parse_input(input)
|
25
|
+
write_input(input)
|
26
|
+
end
|
27
|
+
|
28
|
+
def write_input(input)
|
29
|
+
@input.write(input)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def input_controller
|
35
|
+
if !@input_controller
|
36
|
+
@input_controller = InputController.new
|
37
|
+
@input_controller.view = view
|
38
|
+
end
|
39
|
+
return @input_controller
|
40
|
+
end
|
41
|
+
|
42
|
+
def output_controller
|
43
|
+
if !@output_controller
|
44
|
+
@output_controller = OutputController.new
|
45
|
+
@output_controller.view = view
|
46
|
+
end
|
47
|
+
return @output_controller
|
48
|
+
end
|
49
|
+
|
50
|
+
def view
|
51
|
+
if !@view
|
52
|
+
@view = View.new
|
53
|
+
end
|
54
|
+
return @view
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
body {
|
2
|
+
font-family: "Menlo", monospace;
|
3
|
+
font-size: 13px;
|
4
|
+
}
|
5
|
+
li {
|
6
|
+
list-style: none;
|
7
|
+
white-space: pre-wrap;
|
8
|
+
}
|
9
|
+
pre {
|
10
|
+
position: relative;
|
11
|
+
padding-left: 18px;
|
12
|
+
}
|
13
|
+
pre.output code:before
|
14
|
+
{
|
15
|
+
content: '>';
|
16
|
+
font-weight: bold;
|
17
|
+
left: 7px;
|
18
|
+
position: absolute;
|
19
|
+
opacity: 0.5;
|
20
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
var WcREPL = {
|
2
|
+
addCode: function(code, source) {
|
3
|
+
var template = Handlebars.compile(source);
|
4
|
+
var data = {
|
5
|
+
code: code
|
6
|
+
};
|
7
|
+
return $(template(data)).appendTo("body");
|
8
|
+
},
|
9
|
+
addInput: function(code) {
|
10
|
+
var source = $("#input-template").html();
|
11
|
+
this.addCode(code, source);
|
12
|
+
},
|
13
|
+
addOutput: function(code) {
|
14
|
+
var source = $("#output-template").html();
|
15
|
+
this.addCode(code, source);
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module WebConsole::REPL
|
2
|
+
class InputController < WebConsole::Controller
|
3
|
+
|
4
|
+
attr_accessor :view
|
5
|
+
def initialize
|
6
|
+
end
|
7
|
+
|
8
|
+
def parse_input(input)
|
9
|
+
input = input.dup
|
10
|
+
input.chomp!
|
11
|
+
if !input.strip.empty? # Ignore empty lines
|
12
|
+
@view.add_input(input)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module WebConsole::REPL
|
2
|
+
class OutputController < WebConsole::Controller
|
3
|
+
|
4
|
+
attr_accessor :view
|
5
|
+
def initialize
|
6
|
+
end
|
7
|
+
|
8
|
+
def parse_output(output)
|
9
|
+
output = output.dup
|
10
|
+
output.gsub!(/\x1b[^m]*m/, "") # Remove escape sequences
|
11
|
+
output.chomp!
|
12
|
+
if !output.strip.empty? # Ignore empty lines
|
13
|
+
@view.add_output(output)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module WebConsole::REPL
|
2
|
+
class View < WebConsole::View
|
3
|
+
|
4
|
+
BASE_DIRECTORY = File.join(File.dirname(__FILE__), "..")
|
5
|
+
VIEWS_DIRECTORY = File.join(BASE_DIRECTORY, "view")
|
6
|
+
VIEW_TEMPLATE = File.join(VIEWS_DIRECTORY, 'view.html.erb')
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
self.base_url_path = File.expand_path(BASE_DIRECTORY)
|
10
|
+
load_erb_from_path(VIEW_TEMPLATE)
|
11
|
+
end
|
12
|
+
|
13
|
+
ADD_INPUT_JAVASCRIPT_FUNCTION = "WcREPL.addInput"
|
14
|
+
def add_input(input)
|
15
|
+
do_javascript_function(ADD_INPUT_JAVASCRIPT_FUNCTION, [input])
|
16
|
+
end
|
17
|
+
|
18
|
+
ADD_OUTPUT_JAVASCRIPT_FUNCTION = "WcREPL.addOutput"
|
19
|
+
def add_output(output)
|
20
|
+
do_javascript_function(ADD_OUTPUT_JAVASCRIPT_FUNCTION, [output])
|
21
|
+
end
|
22
|
+
|
23
|
+
# Helpers to allow easy loading of REPL resource even from another base URL
|
24
|
+
|
25
|
+
def repl_header_tags
|
26
|
+
return %Q[
|
27
|
+
#{repl_stylesheet_link_tag}
|
28
|
+
#{repl_handlebars_template_tags}
|
29
|
+
#{shared_javascript_include_tag("handlebars")}
|
30
|
+
#{shared_javascript_include_tag("zepto")}
|
31
|
+
#{repl_javascript_include_tag}
|
32
|
+
]
|
33
|
+
end
|
34
|
+
|
35
|
+
def repl_handlebars_template_tags
|
36
|
+
return %Q[
|
37
|
+
<script id="output-template" type="text/x-handlebars-template">
|
38
|
+
<pre class="output"><code>{{code}}</code></pre>
|
39
|
+
</script>
|
40
|
+
<script id="input-template" type="text/x-handlebars-template">
|
41
|
+
<pre><code>{{code}}</code></pre>
|
42
|
+
</script>]
|
43
|
+
end
|
44
|
+
|
45
|
+
def repl_stylesheet_link_tag
|
46
|
+
path = File.join(repl_base_resource_path, "css/style.css")
|
47
|
+
url = repl_url_for_path(path)
|
48
|
+
return stylesheet_link_tag(url)
|
49
|
+
end
|
50
|
+
|
51
|
+
def repl_javascript_include_tag
|
52
|
+
path = File.join(repl_base_resource_path, "js/wcrepl.js")
|
53
|
+
url = repl_url_for_path(path)
|
54
|
+
return javascript_include_tag(url)
|
55
|
+
end
|
56
|
+
|
57
|
+
require 'open-uri'
|
58
|
+
def repl_url_for_path(path)
|
59
|
+
uri = URI::encode(path)
|
60
|
+
return "file://" + uri
|
61
|
+
end
|
62
|
+
|
63
|
+
def repl_base_resource_path
|
64
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), "../"))
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webconsole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roben Kleene
|
@@ -16,21 +16,42 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- lib/webconsole.rb
|
20
|
-
- lib/webconsole/constants.rb
|
21
|
-
- lib/webconsole/controller.rb
|
22
|
-
- lib/webconsole/module.rb
|
23
|
-
- lib/webconsole/window_manager.rb
|
24
|
-
- lib/applescript/resource_path_for_plugin.scpt
|
25
|
-
- lib/applescript/resource_url_for_plugin.scpt
|
26
19
|
- lib/applescript/close_window.scpt
|
27
20
|
- lib/applescript/do_javascript.scpt
|
28
21
|
- lib/applescript/load_html.scpt
|
29
|
-
- lib/applescript/
|
22
|
+
- lib/applescript/load_html_with_base_url.scpt
|
30
23
|
- lib/applescript/load_plugin.scpt
|
31
24
|
- lib/applescript/plugin_has_windows.scpt
|
32
25
|
- lib/applescript/plugin_read_from_standard_input.scpt
|
26
|
+
- lib/applescript/resource_path_for_plugin.scpt
|
27
|
+
- lib/applescript/resource_url_for_plugin.scpt
|
28
|
+
- lib/applescript/run_plugin.scpt
|
33
29
|
- lib/applescript/window_id_for_plugin.scpt
|
30
|
+
- lib/webconsole/dependencies/css/style.css
|
31
|
+
- lib/webconsole/dependencies/js/wcdependencies.js
|
32
|
+
- lib/webconsole/dependencies/lib/controller.rb
|
33
|
+
- lib/webconsole/dependencies/lib/model.rb
|
34
|
+
- lib/webconsole/dependencies/lib/tester.rb
|
35
|
+
- lib/webconsole/dependencies/lib/view.rb
|
36
|
+
- lib/webconsole/dependencies/views/view.html.erb
|
37
|
+
- lib/webconsole/dependencies.rb
|
38
|
+
- lib/webconsole/extension_constants.rb
|
39
|
+
- lib/webconsole/lib/constants.rb
|
40
|
+
- lib/webconsole/lib/controller.rb
|
41
|
+
- lib/webconsole/lib/module.rb
|
42
|
+
- lib/webconsole/lib/view/erb.rb
|
43
|
+
- lib/webconsole/lib/view/javascript.rb
|
44
|
+
- lib/webconsole/lib/view/resources.rb
|
45
|
+
- lib/webconsole/lib/view.rb
|
46
|
+
- lib/webconsole/lib/window.rb
|
47
|
+
- lib/webconsole/repl/css/style.css
|
48
|
+
- lib/webconsole/repl/js/wcrepl.js
|
49
|
+
- lib/webconsole/repl/lib/input_controller.rb
|
50
|
+
- lib/webconsole/repl/lib/output_controller.rb
|
51
|
+
- lib/webconsole/repl/lib/view.rb
|
52
|
+
- lib/webconsole/repl/view/view.html.erb
|
53
|
+
- lib/webconsole/repl.rb
|
54
|
+
- lib/webconsole.rb
|
34
55
|
homepage:
|
35
56
|
licenses: []
|
36
57
|
metadata: {}
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require 'open-uri'
|
3
|
-
|
4
|
-
module WebConsole
|
5
|
-
class Controller
|
6
|
-
require_relative "constants"
|
7
|
-
require_relative "module"
|
8
|
-
|
9
|
-
attr_reader :name
|
10
|
-
def initialize(delegate = nil, erb_template_path = nil)
|
11
|
-
@delegate = delegate
|
12
|
-
|
13
|
-
template_erb = ERB.new(File.new(erb_template_path).read, nil, '-')
|
14
|
-
html = template_erb.result(binding)
|
15
|
-
|
16
|
-
if @delegate
|
17
|
-
@delegate.load_html(html)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
CSS_EXTENSION = ".css"
|
22
|
-
CSS_PATH_COMPONENT = "css/"
|
23
|
-
def shared_stylesheet_link_tag(resource)
|
24
|
-
uri = URI.join(shared_resources_url, CSS_PATH_COMPONENT, resource + CSS_EXTENSION)
|
25
|
-
return "<link rel=\"stylesheet\" href=\"#{uri.to_s}\" />"
|
26
|
-
end
|
27
|
-
JS_EXTENSION = ".js"
|
28
|
-
JS_PATH_COMPONENT = "js/"
|
29
|
-
def shared_javascript_include_tag(resource)
|
30
|
-
uri = URI.join(shared_resources_url, JS_PATH_COMPONENT, resource + JS_EXTENSION)
|
31
|
-
return "<script type=\"text/javascript\" src=\"#{uri.to_s}\"></script>"
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def shared_resources_url
|
37
|
-
if !@shared_resources_url
|
38
|
-
@shared_resources_url = ENV.has_key?(SHARED_RESOURCES_URL_KEY)? ENV[SHARED_RESOURCES_URL_KEY] : WebConsole::shared_resources_url
|
39
|
-
end
|
40
|
-
return @shared_resources_url
|
41
|
-
end
|
42
|
-
|
43
|
-
class ::String
|
44
|
-
def javascript_escape
|
45
|
-
self.gsub('\\', "\\\\\\\\").gsub("\n", "\\\\n").gsub("'", "\\\\'")
|
46
|
-
end
|
47
|
-
|
48
|
-
def javascript_escape!
|
49
|
-
replace(self.javascript_escape)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|