Sha256: e622a457c3a7a6be4a4c5fb753ce848e85e9f9bc7d1ad3f3b7558574f161285e
Contents?: true
Size: 1.57 KB
Versions: 6
Compression:
Stored size: 1.57 KB
Contents
module WebConsole class Window require_relative "constants" attr_writer :base_url def initialize(window_id = nil) @window_id = window_id end def base_url_path=(value) @base_url = "file://" + value end LOADHTML_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "load_html.scpt") LOADHTMLWITHBASEURL_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "load_html_with_base_url.scpt") def load_html(html) arguments = [html] script = LOADHTML_SCRIPT if @base_url script = LOADHTMLWITHBASEURL_SCRIPT arguments.push(@base_url) end if window_id arguments.push(window_id) end result = WebConsole::run_applescript(script, arguments) if !window_id # This allows a window manager created without a window_id and then be assigned the window_id when load_html is called. @window_id = self.class.window_id_from_result(result) end end DOJAVASCRIPT_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "do_javascript.scpt") def do_javascript(javascript) WebConsole::run_applescript(DOJAVASCRIPT_SCRIPT, [javascript, window_id]) end CLOSEWINDOW_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "close_window.scpt") def close WebConsole::run_applescript(CLOSEWINDOW_SCRIPT, [window_id]) end def window_id if !@window_id && ENV.has_key?(WINDOW_ID_KEY) @window_id = ENV[WINDOW_ID_KEY] end return @window_id end private def self.window_id_from_result(result) return result.split.last.to_i end end end
Version data entries
6 entries across 6 versions & 1 rubygems