This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: html-table, now with DSL syntax!
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Hey, all the cool kids are doing DSL's these days, so naturally I have to follow suit. In my case I adopted a DSL-style syntax for the html-package. Yes! I, too, can call instance_eval(&block)! I wanted this in preparation for my Rails project which I'll be getting back into, now that I'm out of report hell again.
Here was the old syntax:
table = HTML::Table.new do |t|
t.align = 'left'
t.bgcolor = 'red'
t.content = [['foo','bar']]
end
Here's the new syntax:
table = HTML::Table.new do
align 'left'
bgcolor 'red'
content [['foo', 'bar']]
end
In addition, I now support physical tags for content:
table = HTML::Table.new do
content 'foo' do
bold true
italic true
end
end
I also added 'style' and 'class' CSS tag support. You can still use the old syntax, too, if you're worried about backwads compatibility (or if you happen to prefer that style). And now, to add a .to_html_table method to ActiveRecord. :)