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.
Come up with a solution that allows you to puts data out (maybe put that data in a div somewhere), and more importantly, talk to the DOM directly from Ruby. Since the applet can contain Ruby files themselves, we can create a Ruby module that lets you do DOM stuff, that becomes JavaScript which will be eval'd to run in the browser. Or, we just give direct access. I am still playing with what makes sense there
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