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
|
|
|
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...
|
|
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!
|
|