The Artima Developer Community
Sponsored Link

Java Buzz Forum
Running Ruby in the browser via script type="text/ruby"

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
Running Ruby in the browser via script type="text/ruby" Posted: Apr 16, 2007 10:41 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: Running Ruby in the browser via script type="text/ruby"
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement

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

Any direction make sense to you?

Read: Running Ruby in the browser via script type="text/ruby"

Topic: The conspiricy theories of crowds Previous Topic   Next Topic Topic: links for 2007-04-12

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use