Module: Repla
- Defined in:
- lib/repla.rb,
lib/repla/repl.rb,
lib/repla/test.rb,
lib/repla/logger.rb,
lib/repla/lib/view.rb,
lib/repla/lib/module.rb,
lib/repla/lib/window.rb,
lib/repla/dependencies.rb,
lib/repla/lib/constants.rb,
lib/repla/repl/lib/view.rb,
lib/repla/lib/controller.rb,
lib/repla/test/lib/helper.rb,
lib/repla/lib/view/resources.rb,
lib/repla/lib/view/javascript.rb,
lib/repla/test/lib/view_helper.rb,
lib/repla/dependencies/lib/view.rb,
lib/repla/dependencies/lib/model.rb,
lib/repla/dependencies/lib/tester.rb,
lib/repla/repl/lib/input_controller.rb,
lib/repla/logger/test/lib/log_helper.rb,
lib/repla/logger/test/lib/log_tester.rb,
lib/repla/repl/lib/output_controller.rb,
lib/repla/dependencies/lib/controller.rb,
lib/repla/test/packages/Print.replaplugin/Contents/Resources/lib/view.rb,
lib/repla/test/packages/Print.replaplugin/Contents/Resources/lib/controller.rb
Overview
Defined Under Namespace
Modules: Dependencies, Print, REPL, Test
Classes: Controller, Logger, View, Window
Constant Summary
collapse
- LOAD_PLUGIN_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY, 'load_plugin.scpt')
- EXISTS_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY, 'exists.scpt')
- RUN_PLUGIN_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY, 'run_plugin.scpt')
- RUN_PLUGIN_WITH_ENVIRONMENT_SCRIPT =
File.join(
APPLESCRIPT_DIRECTORY, 'run_plugin_with_environment.scpt'
)
- RUN_PLUGIN_IN_SPLIT_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY,
'run_plugin_in_split.scpt')
- WINDOW_ID_FOR_PLUGIN_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY,
'window_id_for_plugin.scpt')
- SPLIT_ID_IN_WINDOW_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY,
'split_id_in_window.scpt')
- SPLIT_ID_IN_WINDOW_LAST_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY,
'split_id_in_window_last.scpt')
- CREATE_WINDOW_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY, 'create_window.scpt')
- RESOURCE_PATH_FOR_PLUGIN_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY,
'resource_path_for_plugin.scpt')
- RESOURCE_URL_FOR_PLUGIN_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY,
'resource_url_for_plugin.scpt')
- PLUGIN_NAME_KEY =
'REPLA_PLUGIN_NAME'.freeze
- SPLIT_ID_KEY =
'REPLA_SPLIT_ID'.freeze
- WINDOW_ID_KEY =
'REPLA_WINDOW_ID'.freeze
- DARK_MODE_KEY =
'REPLA_DARK_MODE'.freeze
- PATH_PREFIX =
'REPLA_PATH_PREFIX'.freeze
- APPLESCRIPT_DIRECTORY =
File.join(__dir__, '../../applescript')
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.debug ⇒ Object
Returns the value of attribute debug.
10
11
12
|
# File 'lib/repla/lib/module.rb', line 10
def debug
@debug
end
|
Class Method Details
.application_exists ⇒ Object
29
30
31
32
|
# File 'lib/repla/lib/module.rb', line 29
def self.application_exists
result = run_applescript(EXISTS_SCRIPT)
result == 'true'
end
|
.clean_path ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/repla/lib/module.rb', line 13
def self.clean_path
return unless ENV.key?(PATH_PREFIX)
prefix = ENV[PATH_PREFIX]
return if prefix.empty?
ENV['PATH'] = ENV['PATH'].delete_prefix(prefix)
ENV.delete(PATH_PREFIX)
end
|
.create_window ⇒ Object
79
80
81
|
# File 'lib/repla/lib/module.rb', line 79
def self.create_window
run_applescript(CREATE_WINDOW_SCRIPT)
end
|
.load_plugin(path) ⇒ Object
24
25
26
|
# File 'lib/repla/lib/module.rb', line 24
def self.load_plugin(path)
run_applescript(LOAD_PLUGIN_SCRIPT, [path])
end
|
.resource_path_for_plugin(name) ⇒ Object
87
88
89
|
# File 'lib/repla/lib/module.rb', line 87
def self.resource_path_for_plugin(name)
run_applescript(RESOURCE_PATH_FOR_PLUGIN_SCRIPT, [name])
end
|
.resource_url_for_plugin(name) ⇒ Object
93
94
95
|
# File 'lib/repla/lib/module.rb', line 93
def self.resource_url_for_plugin(name)
run_applescript(RESOURCE_URL_FOR_PLUGIN_SCRIPT, [name])
end
|
.run_applescript(script, arguments = nil) ⇒ Object
TODO: self.run_applescript should be private but now all of a sudden instances method can’t call private class methods?
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/repla/lib/module.rb', line 99
def self.run_applescript(script, arguments = nil)
command = "/usr/bin/osascript #{script.shell_escape}"
if arguments
command += ' ' + arguments.compact.map(&:to_s).map do |x|
x.shell_escape
end.join(' ')
end
puts command if @debug
result = `#{command}`
result.chomp!
return nil if result.empty?
return result.to_i if result.integer?
return result.to_f if result.float?
result
end
|
.run_plugin(name, directory = nil, arguments = nil) ⇒ Object
35
36
37
38
39
40
|
# File 'lib/repla/lib/module.rb', line 35
def self.run_plugin(name, directory = nil, arguments = nil)
parameters = [name]
parameters.push(directory) unless directory.nil?
parameters += arguments unless arguments.nil?
run_applescript(RUN_PLUGIN_SCRIPT, parameters)
end
|
.run_plugin_in_split(name, window_id, split_id) ⇒ Object
52
53
54
55
|
# File 'lib/repla/lib/module.rb', line 52
def self.run_plugin_in_split(name, window_id, split_id)
parameters = [name, window_id, split_id]
run_applescript(RUN_PLUGIN_IN_SPLIT_SCRIPT, parameters)
end
|
.run_plugin_with_environment(name, environment) ⇒ Object
45
46
47
48
|
# File 'lib/repla/lib/module.rb', line 45
def self.run_plugin_with_environment(name, environment)
parameters = [name, environment]
run_applescript(RUN_PLUGIN_WITH_ENVIRONMENT_SCRIPT, parameters)
end
|
.split_id_in_window(window_id, plugin_name = nil) ⇒ Object
65
66
67
68
69
|
# File 'lib/repla/lib/module.rb', line 65
def self.split_id_in_window(window_id, plugin_name = nil)
arguments = [window_id]
arguments.push(plugin_name) unless plugin_name.nil?
run_applescript(SPLIT_ID_IN_WINDOW_SCRIPT, arguments)
end
|
.split_id_in_window_last(window_id) ⇒ Object
73
74
75
76
|
# File 'lib/repla/lib/module.rb', line 73
def self.split_id_in_window_last(window_id)
arguments = [window_id]
run_applescript(SPLIT_ID_IN_WINDOW_LAST_SCRIPT, arguments)
end
|
.window_id_for_plugin(name) ⇒ Object
59
60
61
|
# File 'lib/repla/lib/module.rb', line 59
def self.window_id_for_plugin(name)
run_applescript(WINDOW_ID_FOR_PLUGIN_SCRIPT, [name])
end
|