webconsole 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/applescript/close_window.scpt +0 -0
- data/lib/applescript/do_javascript.scpt +0 -0
- data/lib/applescript/load_html.scpt +0 -0
- data/lib/applescript/load_plugin.scpt +0 -0
- data/lib/applescript/plugin_has_windows.scpt +0 -0
- data/lib/applescript/plugin_read_from_standard_input.scpt +0 -0
- data/lib/applescript/resource_path_for_plugin.scpt +0 -0
- data/lib/applescript/resource_url_for_plugin.scpt +0 -0
- data/lib/applescript/run_plugin.scpt +0 -0
- data/lib/applescript/window_id_for_plugin.scpt +0 -0
- data/lib/webconsole.rb +7 -0
- data/lib/webconsole/constants.rb +15 -0
- data/lib/webconsole/controller.rb +55 -0
- data/lib/webconsole/module.rb +97 -0
- data/lib/webconsole/window_manager.rb +58 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YWNkNmQwOTQ5ODQ2Nzk3Yjc0M2E3YmI4MTJkNWZmNzRiN2FkMTlmYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NWEwZTEzMjViNzYwMDU1NzlhZDkyNzNmZjUxMzlmYmE3OTU5ZjU5OA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTQyZjQwZDUyYTNiNjVlYjc0ZjM5MzkyODdkOGNmYTM1ZDI2NjE5NzZiMmQ4
|
10
|
+
MWI3YTNkYWZmZWY5ZjBjNTY5ZDJhM2UyNTM5NDQ1NjJjMTM1NjQwMDdjOTNh
|
11
|
+
MDA0NWFkNjRhMGEwYTgyYmI5NTYyMGU3YTE2YWY4M2U3Yzc2NTk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjgwY2MyZmJhNjNkYWM4Zjc2YjE4MjEyZDIxZTEwMjEwZWU3Y2U4ZmIxMTdh
|
14
|
+
MWVjMjQ2YzVlMmM5YTQwODM4YTU2ZjMwMzc2Mjc2NjZiNTA5ODIzMjAwODFk
|
15
|
+
Y2FiOGZmY2Y3NjNmOGRiMGZhMDMyODMwNWY5Mzk2MjljMTZmNTE=
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/webconsole.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module WebConsole
|
2
|
+
# Keys
|
3
|
+
PLUGIN_NAME_KEY = 'WC_PLUGIN_NAME'
|
4
|
+
WINDOW_ID_KEY = 'WC_WINDOW_ID'
|
5
|
+
SHARED_RESOURCES_PATH_KEY = 'WC_SHARED_RESOURCES_PATH'
|
6
|
+
SHARED_RESOURCES_URL_KEY = 'WC_SHARED_RESOURCES_URL'
|
7
|
+
|
8
|
+
# Files
|
9
|
+
WINDOW_MANAGER_FILE = File.join(File.dirname(__FILE__), "window_manager")
|
10
|
+
CONTROLLER_FILE = File.join(File.dirname(__FILE__), "controller")
|
11
|
+
MODULE_FILE = File.join(File.dirname(__FILE__), "module")
|
12
|
+
|
13
|
+
# Directories
|
14
|
+
APPLESCRIPT_DIRECTORY = File.join(File.dirname(__FILE__), "..", "applescript")
|
15
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module WebConsole
|
5
|
+
class Controller
|
6
|
+
WEBCONSOLE_CONSTANTS = File.join(File.dirname(__FILE__), "constants")
|
7
|
+
require WEBCONSOLE_CONSTANTS
|
8
|
+
require MODULE_FILE
|
9
|
+
|
10
|
+
attr_reader :name
|
11
|
+
def initialize(delegate = nil, erb_template_path = nil)
|
12
|
+
@delegate = delegate
|
13
|
+
|
14
|
+
template_erb = ERB.new(File.new(erb_template_path).read, nil, '-')
|
15
|
+
html = template_erb.result(binding)
|
16
|
+
|
17
|
+
if @delegate
|
18
|
+
@delegate.load_html(html)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
CSS_EXTENSION = ".css"
|
23
|
+
CSS_PATH_COMPONENT = "css/"
|
24
|
+
def shared_stylesheet_link_tag(resource)
|
25
|
+
uri = URI.join(shared_resources_url, CSS_PATH_COMPONENT, resource + CSS_EXTENSION)
|
26
|
+
return "<link rel=\"stylesheet\" href=\"#{uri.to_s}\" />"
|
27
|
+
end
|
28
|
+
JS_EXTENSION = ".js"
|
29
|
+
JS_PATH_COMPONENT = "js/"
|
30
|
+
def shared_javascript_include_tag(resource)
|
31
|
+
uri = URI.join(shared_resources_url, JS_PATH_COMPONENT, resource + JS_EXTENSION)
|
32
|
+
return "<script type=\"text/javascript\" src=\"#{uri.to_s}\"></script>"
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def shared_resources_url
|
38
|
+
if !@shared_resources_url
|
39
|
+
@shared_resources_url = ENV.has_key?(SHARED_RESOURCES_URL_KEY)? ENV[SHARED_RESOURCES_URL_KEY] : WebConsole::shared_resources_url
|
40
|
+
end
|
41
|
+
return @shared_resources_url
|
42
|
+
end
|
43
|
+
|
44
|
+
class ::String
|
45
|
+
def javascript_escape
|
46
|
+
self.gsub('\\', "\\\\\\\\").gsub("\n", "\\\\n").gsub("'", "\\\\'")
|
47
|
+
end
|
48
|
+
|
49
|
+
def javascript_escape!
|
50
|
+
replace(self.javascript_escape)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'Shellwords'
|
2
|
+
module WebConsole
|
3
|
+
LOAD_PLUGIN_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "load_plugin.scpt")
|
4
|
+
def self.load_plugin(path)
|
5
|
+
self.run_applescript(LOAD_PLUGIN_SCRIPT, [path])
|
6
|
+
end
|
7
|
+
|
8
|
+
RUN_PLUGIN_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "run_plugin.scpt")
|
9
|
+
def self.run_plugin(name, directory = nil, arguments = nil)
|
10
|
+
parameters = [name]
|
11
|
+
if directory
|
12
|
+
parameters.push(directory)
|
13
|
+
end
|
14
|
+
if arguments
|
15
|
+
parameters = parameters + arguments
|
16
|
+
end
|
17
|
+
self.run_applescript(RUN_PLUGIN_SCRIPT, parameters)
|
18
|
+
end
|
19
|
+
|
20
|
+
PLUGIN_HAS_WINDOWS_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "plugin_has_windows.scpt")
|
21
|
+
def self.plugin_has_windows(name)
|
22
|
+
result = self.run_applescript(PLUGIN_HAS_WINDOWS_SCRIPT, [name])
|
23
|
+
result.chomp!
|
24
|
+
if result == "true"
|
25
|
+
return true
|
26
|
+
else
|
27
|
+
return false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
WINDOW_ID_FOR_PLUGIN_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "window_id_for_plugin.scpt")
|
32
|
+
def self.window_id_for_plugin(name)
|
33
|
+
result = self.run_applescript(WINDOW_ID_FOR_PLUGIN_SCRIPT, [name])
|
34
|
+
result.chomp!
|
35
|
+
return result
|
36
|
+
end
|
37
|
+
|
38
|
+
# Shared Resources
|
39
|
+
|
40
|
+
RESOURCE_PATH_FOR_PLUGIN_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "resource_path_for_plugin.scpt")
|
41
|
+
def self.resource_path_for_plugin(name)
|
42
|
+
result = self.run_applescript(RESOURCE_PATH_FOR_PLUGIN_SCRIPT, [name])
|
43
|
+
result.chomp!
|
44
|
+
return result
|
45
|
+
end
|
46
|
+
|
47
|
+
# Shared Resource Path
|
48
|
+
|
49
|
+
SHARED_RESOURCES_PLUGIN_NAME = "Shared Resources"
|
50
|
+
SHARED_TEST_RESOURCES_PLUGIN_NAME = "Shared Test Resources"
|
51
|
+
def self.shared_resources_path
|
52
|
+
return WebConsole::resource_path_for_plugin(SHARED_RESOURCES_PLUGIN_NAME)
|
53
|
+
end
|
54
|
+
def self.shared_test_resources_path
|
55
|
+
return WebConsole::resource_path_for_plugin(SHARED_TEST_RESOURCES_PLUGIN_NAME)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.shared_resource(resource)
|
59
|
+
return File.join(self.shared_resources_path, resource)
|
60
|
+
end
|
61
|
+
def self.shared_test_resource(resource)
|
62
|
+
return File.join(self.shared_test_resources_path, resource)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Shared Resource URL
|
66
|
+
|
67
|
+
RESOURCE_URL_FOR_PLUGIN_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "resource_url_for_plugin.scpt")
|
68
|
+
def self.resource_url_for_plugin(name)
|
69
|
+
result = self.run_applescript(RESOURCE_URL_FOR_PLUGIN_SCRIPT, [name])
|
70
|
+
result.chomp!
|
71
|
+
return result
|
72
|
+
end
|
73
|
+
def self.shared_resources_url
|
74
|
+
return WebConsole::resource_url_for_plugin(SHARED_RESOURCES_PLUGIN_NAME)
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
PLUGIN_READ_FROM_STANDARD_INPUT_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "plugin_read_from_standard_input.scpt")
|
79
|
+
def self.plugin_read_from_standard_input(name, text)
|
80
|
+
self.run_applescript(PLUGIN_READ_FROM_STANDARD_INPUT_SCRIPT, [name, text])
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def self.run_applescript(script, arguments = nil)
|
86
|
+
command = "osascript #{Shellwords.escape(script)}"
|
87
|
+
if arguments
|
88
|
+
arguments.each { |argument|
|
89
|
+
if argument
|
90
|
+
argument = argument.to_s
|
91
|
+
command = command + " " + Shellwords.escape(argument)
|
92
|
+
end
|
93
|
+
}
|
94
|
+
end
|
95
|
+
return `#{command}`
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module WebConsole
|
2
|
+
class WindowManager
|
3
|
+
WEBCONSOLE_CONSTANTS = File.join(File.dirname(__FILE__), "constants")
|
4
|
+
require WEBCONSOLE_CONSTANTS
|
5
|
+
|
6
|
+
attr_writer :base_url
|
7
|
+
|
8
|
+
def initialize(window_id = nil)
|
9
|
+
@window_id = window_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def base_url_path=(value)
|
13
|
+
@base_url = "file://" + value
|
14
|
+
end
|
15
|
+
|
16
|
+
LOADHTML_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "load_html.scpt")
|
17
|
+
def load_html(html)
|
18
|
+
arguments = [html]
|
19
|
+
|
20
|
+
if @base_url
|
21
|
+
arguments.push(@base_url)
|
22
|
+
end
|
23
|
+
|
24
|
+
if window_id
|
25
|
+
arguments.push(window_id)
|
26
|
+
end
|
27
|
+
|
28
|
+
result = WebConsole::run_applescript(LOADHTML_SCRIPT, arguments)
|
29
|
+
if !window_id
|
30
|
+
# This allows a window manager created without a window_id and then be assigned the window_id when load_html is called.
|
31
|
+
@window_id = self.class.window_id_from_result(result)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
DOJAVASCRIPT_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "do_javascript.scpt")
|
36
|
+
def do_javascript(javascript)
|
37
|
+
WebConsole::run_applescript(DOJAVASCRIPT_SCRIPT, [javascript, window_id])
|
38
|
+
end
|
39
|
+
|
40
|
+
CLOSEWINDOW_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "close_window.scpt")
|
41
|
+
def close
|
42
|
+
WebConsole::run_applescript(CLOSEWINDOW_SCRIPT, [window_id])
|
43
|
+
end
|
44
|
+
|
45
|
+
def window_id
|
46
|
+
if !@window_id && ENV.has_key?(WINDOW_ID_KEY)
|
47
|
+
@window_id = ENV[WINDOW_ID_KEY]
|
48
|
+
end
|
49
|
+
return @window_id
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def self.window_id_from_result(result)
|
55
|
+
return result.split.last.to_i
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webconsole
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roben Kleene
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Bridge from Ruby to AppleScript to control Web Console
|
14
|
+
email: roben@1percenter.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
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
|
+
- lib/applescript/close_window.scpt
|
27
|
+
- lib/applescript/do_javascript.scpt
|
28
|
+
- lib/applescript/load_html.scpt
|
29
|
+
- lib/applescript/run_plugin.scpt
|
30
|
+
- lib/applescript/load_plugin.scpt
|
31
|
+
- lib/applescript/plugin_has_windows.scpt
|
32
|
+
- lib/applescript/plugin_read_from_standard_input.scpt
|
33
|
+
- lib/applescript/window_id_for_plugin.scpt
|
34
|
+
homepage:
|
35
|
+
licenses: []
|
36
|
+
metadata: {}
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 2.0.3
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Web Console helper gem
|
57
|
+
test_files: []
|