Class: Ichabod::Runtime
- Inherits:
-
Object
- Object
- Ichabod::Runtime
- Defined in:
- lib/ichabod/runtime.rb
Instance Attribute Summary collapse
-
#webView ⇒ Object
readonly
Returns the value of attribute webView.
Instance Method Summary collapse
- #eval(js) ⇒ Object
- #eval_file(file) ⇒ Object
- #html_source ⇒ Object
-
#initialize(options = {}) ⇒ Runtime
constructor
A new instance of Runtime.
- #load_dom(dom, base_url = nil) ⇒ Object
- #navigate(url) ⇒ Object (also: #open)
- #run ⇒ Object
- #to_s ⇒ Object
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( = {}) @webView = WebView.new @webView.setFrameLoadDelegate(Delegate::Load.new(self)) @webView.setUIDelegate(Delegate::UI.new(self)) load_dom([:dom]) if [:dom] end |
Instance Attribute Details
#webView ⇒ Object (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.(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_source ⇒ Object
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 |
#navigate(url) ⇒ Object Also known as: open
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.(url) end url = NSURL.alloc.initWithString(url) @webView.mainFrame.loadRequest(NSURLRequest.requestWithURL(url)) self end |
#run ⇒ Object
52 53 54 55 56 |
# File 'lib/ichabod/runtime.rb', line 52 def run unless NSApplication.sharedApplication.running? NSApplication.sharedApplication.run end end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/ichabod/runtime.rb', line 44 def to_s @dom ? html_source : super end |