Class: WebConsole::WindowManager

Inherits:
Object
  • Object
show all
Defined in:
lib/webconsole/window_manager.rb

Constant Summary collapse

WEBCONSOLE_CONSTANTS =
File.join(File.dirname(__FILE__), "constants")
LOADHTML_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY, "load_html.scpt")
DOJAVASCRIPT_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY, "do_javascript.scpt")
CLOSEWINDOW_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY, "close_window.scpt")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window_id = nil) ⇒ WindowManager

Returns a new instance of WindowManager.



8
9
10
# File 'lib/webconsole/window_manager.rb', line 8

def initialize(window_id = nil)
  @window_id = window_id
end

Instance Attribute Details

#base_url=(value) ⇒ Object (writeonly)

Sets the attribute base_url

Parameters:

  • value

    the value to set the attribute base_url to.



6
7
8
# File 'lib/webconsole/window_manager.rb', line 6

def base_url=(value)
  @base_url = value
end

Class Method Details

.window_id_from_result(result) ⇒ Object



54
55
56
# File 'lib/webconsole/window_manager.rb', line 54

def self.window_id_from_result(result)
  return result.split.last.to_i
end

Instance Method Details

#base_url_path=(value) ⇒ Object



12
13
14
# File 'lib/webconsole/window_manager.rb', line 12

def base_url_path=(value)
  @base_url = "file://" + value
end

#closeObject



41
42
43
# File 'lib/webconsole/window_manager.rb', line 41

def close
  WebConsole::run_applescript(CLOSEWINDOW_SCRIPT, [window_id])
end

#do_javascript(javascript) ⇒ Object



36
37
38
# File 'lib/webconsole/window_manager.rb', line 36

def do_javascript(javascript)
  WebConsole::run_applescript(DOJAVASCRIPT_SCRIPT, [javascript, window_id])
end

#load_html(html) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/webconsole/window_manager.rb', line 17

def load_html(html)
  arguments = [html]

  if @base_url
    arguments.push(@base_url)
  end

  if window_id
    arguments.push(window_id)
  end

  result = WebConsole::run_applescript(LOADHTML_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

#window_idObject



45
46
47
48
49
50
# File 'lib/webconsole/window_manager.rb', line 45

def window_id
  if !@window_id && ENV.has_key?(WINDOW_ID_KEY)
    @window_id = ENV[WINDOW_ID_KEY]
  end
  return @window_id
end