The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
I need a DOM wrapper!

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
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
I need a DOM wrapper! Posted: Jan 16, 2006 9:39 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: I need a DOM wrapper!
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
Dealing with various DOM elements in Rails is proving to be a pain. Although the helpers that Rails provides are certainly useful, they start to fall down whenever I want to do advanced configuration. What I *really* want is to have each DOM object represented by a Ruby class. Here's my theoretical syntax:
require "html/dom"
include HTML

select = DOM::Select.new{ |s|
   s.id         = "foo"
   s.selected   = 2
   s.options    = ["matz", "guido", "larry"]
   s.onChange   = "location = " + s.options[s.selectedIndex]
}

Let's assume each DOM object has a .html method that generates the raw html. In theory then, select.html would magically generate the following:
<select id='foo' onChange="location = this.options[this.selectedIndex].value;">
   <option value="matz">matz
   <option value="guido">guido
   <option value="larry" selected>larry
</select>

To assign different values, you would replace the value pased to s.options with a hash:
...
s.options = {1=>"matz", 2=>"guido", 3=>"larry"}
...
<option value='1'>matz
<option value='2'>guido
<option value='3' selected>larry
...

What isn't immediately clear to me is how to properly handle this and document. Maybe someone smarter than me could work this out. :)

Read: I need a DOM wrapper!

Topic: How to exclude an action from the controller's layout processing Previous Topic   Next Topic Topic: Putting RubyRiver together

Sponsored Links



Google
  Web Artima.com   

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