Class: Ichabod::Runtime

Inherits:
Object
  • Object
show all
Defined in:
lib/ichabod/runtime.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runtime

Returns a new instance of Runtime.



7
8
9
10
11
12
# File 'lib/ichabod/runtime.rb', line 7

def initialize(options = {})
  @webView = WebView.new      
  @webView.setFrameLoadDelegate(Delegate::Load.new(self))
  @webView.setUIDelegate(Delegate::UI.new(self))
  load_dom(options[:dom]) if options[:dom]      
end

Instance Attribute Details

#webViewObject (readonly)

Returns the value of attribute webView.



5
6
7
# File 'lib/ichabod/runtime.rb', line 5

def webView
  @webView
end

Instance Method Details

#eval(js) ⇒ Object



26
27
28
# File 'lib/ichabod/runtime.rb', line 26

def eval(js)
  @webView.windowScriptObject.evaluateWebScript(js)
end

#eval_file(file) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/ichabod/runtime.rb', line 30

def eval_file(file)
  file = File.expand_path(file.to_s, Ichabod::JS_PATH)
  if File.exists? file
    eval File.read(file)
  elsif File.exists? file + '.js'
    eval File.read(file + '.js')
  end
end

#html_sourceObject



48
49
50
# File 'lib/ichabod/runtime.rb', line 48

def html_source
  eval("document.documentElement.outerHTML")
end

#load_dom(dom, base_url = nil) ⇒ Object



39
40
41
42
# File 'lib/ichabod/runtime.rb', line 39

def load_dom(dom, base_url = nil)
  @dom = File.exists?(dom) ? File.read(dom) : dom
  @webView.mainFrame.loadHTMLString(@dom, baseURL:base_url)
end


14
15
16
17
18
19
20
21
22
23
# File 'lib/ichabod/runtime.rb', line 14

def navigate(url)
  # Local file check
  unless url =~ /^http/
    url = "file://" + File.expand_path(url)
  end
  
  url = NSURL.alloc.initWithString(url)
  @webView.mainFrame.loadRequest(NSURLRequest.requestWithURL(url))
  self
end

#runObject



52
53
54
55
56
# File 'lib/ichabod/runtime.rb', line 52

def run
  unless NSApplication.sharedApplication.running?
    NSApplication.sharedApplication.run
  end
end

#to_sObject



44
45
46
# File 'lib/ichabod/runtime.rb', line 44

def to_s
  @dom ? html_source : super
end