[MacRuby-devel] Visibility of ruby methods to objective-C delegates
Michael Pitra
michael at pitra.at
Tue Feb 2 14:18:16 PST 2010
Hi Eloy,
it is not related to hotcocoa since my original application is not using it - this example was taken because
it was that simple that it fitted in some lines of code.
The question is rather, if I should attach a stripped down version of my app for better testing purposes.
Thanks,
Michael
Am 02.02.2010 um 22:22 schrieb Eloy Duran:
> Hi Michael,
>
> Could you try if the webview/js bridge part of the code works, or doesn't, in a normal MacRuby application? If it doesn't work, please file a ticket on https://www.macruby.org/trac/newticket. If it does, then it might be a HotCocoa problem, in which case please file a ticket here: http://github.com/richkilmer/hotcocoa/issues
>
> Thanks,
> Eloy
>
> On 1 feb 2010, at 15:51, Michael Pitra wrote:
>
>>
>> I'm trying to do something similar to this example:
>>
>> http://code.reflectivepixel.com/post/103638573/require-hotcocoa-framework-webkit-class
>>
>> Code excerpt:
>>
>> require 'hotcocoa'
>> framework 'webkit'
>> class Application
>> include HotCocoa
>> FULL={:expand => [:width,:height]}
>> BASE=<<-END
>> <html><head><style type="text/css">
>> * { font-family: Monaco; }
>> </style><script type="text/javascript">
>> function say(arg) { window.TheBridge.click(arg);}
>> </script>
>> </head><body><h3>Ruby JavaScript Bridge</h3>
>> <a href="#" onclick="say('hi')">tell</a></body></html>
>> END
>> def click(arg) #called from javascript
>> root = document.createElement("div");
>> root.innerHTML="javascript tells ruby: #{arg}"
>> document.body.appendChild(root)
>> end
>> def document
>> @web_view.mainFrame.DOMDocument
>> end
>> def self.webScriptNameForSelector(sel) #hide : in name
>> sel.to_s.sub(/:$/,'') if is_available_selector?(sel)
>> end
>> def self.isSelectorExcludedFromWebScript(sel)
>> ! is_available_selector?(sel)
>> end
>> def self.isKeyExcludedFromWebScript(key)
>> true
>> end
>> def self.is_available_selector?(sel)
>> ['click:'].include?(sel.to_s)
>> end
>> def start
>> application :name => "MyBridge" do |app|
>> app.delegate = self
>> window :title => "MyBridge",
>> :frame => [10, 620, 330, 230] do |win|
>> win << @web_view=web_view(:layout => FULL) do |wv|
>> wv.mainFrame.loadHTMLString BASE, baseURL: nil
>> wv.frameLoadDelegate=self
>> wso=wv.windowScriptObject #make visible to JS
>> wso.setValue(self, forKey:"TheBridge")
>> end
>> win.will_close { exit }
>> end
>> end
>> end
>> end
>> Application.new.start
>>
>> Clicking on "tell" does not work. It seems, that the selector for "click:" is not found. When logging the selector values in self.isSelectorExcludedFromWebScript(sel), the "click:" selector is not amongst the results.
>>
>> What am I missing here?
>>
>> Regards,
>> Michael
>>
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100202/a91d9290/attachment-0001.html>
More information about the MacRuby-devel
mailing list