July 13, 2008
JavaScript with RubyCocoa
After doing some hacking on Prototype yesterday (to fix a Rails issue that’s been bugging me for ages — I’ll post more about that soon), I got to wondering if there might be a nicer way to run JavaScript tests from Rails.
A little research and some tinkering produced this:
#!/usr/bin/ruby
require 'osx/cocoa'
OSX.require_framework 'WebKit'
web_view = OSX::WebView.alloc.init
script_object = web_view.windowScriptObject
p script_object.evaluateWebScript("14 * Math.sin(0.3)").to_f
Seems like a good starting point for something, although exception handling is a problem.