This post originated from an RSS feed registered with Ruby Buzz
by James Britt.
Original Post: Ruby + Konfabulator
Feed Title: James Britt: Ruby Development
Feed URL: http://feeds.feedburner.com/JamesBritt-Home
Feed Description: James Britt: Playing with better toys
I recently got around to installing Konfabulator and playing round with assorted widgets.
One that caught my eye was the Allgäu Web-cams viewer by Thomas Heinbach. Nice as the assorted images are, though, I was disappointed to find they did not include Kempten, a town dear to my heart and offering a Rathausplatz Web cam.
It didn't take long to dissemble the widget, see how it works, and hack in support for Kempten. It was also interesting to see just how the widget manages to get such images.
When Konfabulator is installed (on Windows, at least), it includes a Unix shell (sh) and and assorted Unix libs and utilities (cat, ln, make). Interesting. This may be to provide some compatibility layer with Unix-based Mac Konfabulator.
Widget behavior is controlled using JavaScript, bundled up in XML files (and, optionally, external .js files which my be loaded from the main widget code).
The Web cam widget fetches images by invoking curl.
As an experiment I swapped out the image fetching line with a command-line call to Ruby (using open-uri). It worked fine.
Much as I like ECMAScript, I wondering how one can write Konfabulator code in Ruby. Certainly one option is to have the widget make XML-RPC (or simply RESTful POX calls) to some Ruby service.
I believe it is possible, on Win32, to invoke ActiveX controls. See this ruby-talk message. So one could call into ActiveRubyScript.
There is also Kapsules, though I've yet to try it. And Ruby-EFL bindings, but I am unaware of how to get this to play well on Win32.
(I wonder if those Unix utils are cygwn-based, or MinGW, and if one could simply compile Ruby as a standalone app and drop it in with the other binaries in Konfabulator\UnixUtils\usr\local\wbin.)
If one wanted to ship a Ruby-based widget, though, to current Konfabulator users, one possibility would be to bundle up all needed Ruby fies with RubyScript2Exe, and launch some WEBrick service via the widget script CLI to handle the core processing and exchange messages with the JavaScript in the widget. If you were clever enough you could probably bundle up the SQLite3 DLL (again, I'm talking Windows; I assume something similar is just as doable on the Mac) and offer your widgets persistent storage.
Perhaps run a Nitro app that speaks XML and leaves the rendering to Konfabulator. Or, even simpler, use Catapult.
Well, except there's a catch: Konfabulator does nor expose an XML parser via JavaScript. Sadness. I went looking trough the code for a "Check for updated widgets" widget, and it uses some gnarly calls to indexof to parse RSS.
But, a quick search revealed the use of eval(). Ah so. It may very well be possible to have Catapult simply return JSON and have the widget just eval the response. No need for XML. (Just to clarify: indeed, Catapult will have no problem emitting JSON or anything else. Just need to see if running eval over the JSON does the Right Thing.)
I may look at hooking Catapult to Orbjson, or run Orbjson with Nitro under WEBrick as a service. Then just leave the GUI logic to Konfabulator