intertwingly

It’s just data

Opal looks very promising


W

Opal is a Ruby to JavaScript compiler.  The team working on it are not only working to bring access to JavaScript libraries (like jquery) but also to replicate Ruby library interfaces.  Walking through a simple example...

This script defines two types of responses, HTML and JSON.

The HTML response define a simple table and a script.  The script is defined in Ruby, but is converted to JavaScript before sending to the browser.  The script itself issues three HTTP request and updates individual cells in the table when it gets responses.

Those requests produce JSON replies, depending on the individual field requested.  Both the client and server scripts in this example involve DOM traversal.  One uses JQuery style methods (find).  The other nokogiri (at and search).

An alternative to opal-jquery is opal-browser.  The latter provides a more Markaby/Nokogiri style interface to the DOM.

To run:

gem install wunderbar nokogumbo opal opal-jquery sourcify
ruby watch.rb --port=3030

If your web server is set up to handle CGI, you can drop this script directly into your document directory and run it.  If you do so, the requests will all be handled in parallel.