Sha256: f79552f8b684f1c189bd57a965b777109d903354826f6bce8ec1b362d11fd053
Contents?: true
Size: 1.45 KB
Versions: 2
Compression:
Stored size: 1.45 KB
Contents
# http://developer.apple.com/documentation/Cocoa/Reference/WebKit/ObjC_classic/index.html module Ichabod class Runtime attr_reader :webView 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 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 alias_method :open, :navigate def eval(js) @webView.windowScriptObject.evaluateWebScript(js) end 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 def load_dom(dom, base_url = nil) @dom = File.exists?(dom) ? File.read(dom) : dom @webView.mainFrame.loadHTMLString(@dom, baseURL:base_url) end def to_s @dom ? html_source : super end def html_source eval("document.documentElement.outerHTML") end def run unless NSApplication.sharedApplication.running? NSApplication.sharedApplication.run end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ichabod-0.0.2 | lib/ichabod/runtime.rb |
ichabod-0.0.1 | lib/ichabod/runtime.rb |