From 23e46358932ab28d95e9d39f6eae8956312743b6 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Thu, 25 Jun 2009 22:20:34 -0700 Subject: [PATCH] add amazing dom loading --- lib/lyndon/delegate.rb | 7 +++++++ lib/lyndon/runtime.rb | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 lib/lyndon/delegate.rb diff --git a/lib/lyndon/delegate.rb b/lib/lyndon/delegate.rb new file mode 100644 index 0000000..d5c8fa1 --- /dev/null +++ b/lib/lyndon/delegate.rb @@ -0,0 +1,7 @@ +module Lyndon + class Delegate + def webView(sender, didFinishLoadForFrame:frame) + NSApplication.sharedApplication.stop(self) + end + end +end diff --git a/lib/lyndon/runtime.rb b/lib/lyndon/runtime.rb index 9611bb8..633f7a5 100644 --- a/lib/lyndon/runtime.rb +++ b/lib/lyndon/runtime.rb @@ -2,10 +2,20 @@ module Lyndon class Runtime - def initialize + 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 + end + + 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 def eval(js)