I played around with getting Ruby to work in the browser while watching some cheesy TV this weekend.
I was able to get things slightly working, and put this work in progress up on Google Code here.
That link sends you to a page that will evaluate Ruby for you, both from a script tag, and from your own input.
If you take a look at the top of the file, you will see:
<script type="text/ruby"> #class Foo; def initialize; @foo = 'whee'; end; end; f = Foo.new; f Time.now </script>
This script is found by the Ruby in the browser system, and is run through JRuby via a little applet. The page takes the output at the end and throws it into the container HTML on the right.
You can also edit the text area at the bottom left and run your own Ruby code, and the output will be placed on the right too.
Now, this is just the first baby step to get to something feature full like:
<script type="text/ruby"> document.ready do |dom| dom["table tr"] <<"<td>test</td>" end </script>
Just being able to run some Ruby doesn’t mean much. We need to give it rich support for the browser to be able to interact with the DOM and Ajax libraries to do cool things, using the power of Ruby.
So, there are a lot of TODOs here:
- The applet is a download of JRuby complete, which is huge, and isn’t all needed. I need to work with the JRuby folk to produce a slimmed down applet version.
- Only tested in Firefox. There are some known issues in Safari.
- I am lazily using an applet tag instead of the magic object/embed stuff that would make this work in other places
Any direction make sense to you?