Class: Lyndon::Runtime
- Inherits:
-
Object
- Object
- Lyndon::Runtime
- Defined in:
- lib/lyndon/runtime.rb
Instance Method Summary collapse
- #eval(js) ⇒ Object
- #eval_file(file) ⇒ Object
- #html_source ⇒ Object
-
#initialize(dom = nil) ⇒ Runtime
constructor
A new instance of Runtime.
- #load_dom(dom, base_url = nil) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(dom = nil) ⇒ Runtime
Returns a new instance of Runtime.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/lyndon/runtime.rb', line 5 def initialize(dom = nil) @webView = WebView.new @webView.setFrameLoadDelegate(Delegate.new) @scripter = @webView.windowScriptObject @scripter.setValue(Ruby.new, forKey:"Ruby") load_dom(dom) if dom eval_file File.dirname(__FILE__) + '/../js/lyndon' end |
Instance Method Details
#eval(js) ⇒ Object
16 17 18 |
# File 'lib/lyndon/runtime.rb', line 16 def eval(js) @scripter.evaluateWebScript(js) end |
#eval_file(file) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/lyndon/runtime.rb', line 20 def eval_file(file) if File.exists? file = File.(file.to_s) eval File.read(file) elsif File.exists? file + '.js' eval File.read(file + '.js') end end |
#html_source ⇒ Object
38 39 40 |
# File 'lib/lyndon/runtime.rb', line 38 def html_source '<html>'+eval("document.documentElement.innerHTML")+'</html>' end |
#load_dom(dom, base_url = nil) ⇒ Object
28 29 30 31 32 |
# File 'lib/lyndon/runtime.rb', line 28 def load_dom(dom, base_url = nil) @dom = File.exists?(dom) ? File.read(dom) : dom @webView.mainFrame.loadHTMLString(@dom, baseURL:base_url) NSApplication.sharedApplication.run end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/lyndon/runtime.rb', line 34 def to_s @dom ? html_source : super end |