This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: Less method_missing in Markaby
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
In the new Markaby branch, I’ve got a list of valid tags and attributes generated from the XHTML 1.0 Transitional and XHTML 1.0 Strict DTDs. Which means Markaby can validate as you go.
>> div :styl => 'margin:10px' do
>> h1 "Never To Be Seen"
>> end
Markaby::InvalidXhtmlError: no attribute `styl' on div elements
>> salect :onclick => 'javascript:alert("GIMMICK!")' do
>> option '- please -'
>> end
NoMethodError: no such method `salect'
However, there is no check right now to make sure that the nesting is right. It’ll let you put a tbody in a div, for example. But it’s a start.
The implicit stringification of tags and helpers is working fantastic now as well. Can ERB compete with this (from CampSh [103]):
strong(author) + " worked on: " +
cmds.map { |cmd|
a cmd.name, :href => R(Show, cmd.name) }.join(", ")
There’s little need for the capture statement any longer. If you need to force a capture, call to_s on the HTML fragment.
div {
@a = small('Miniature').to_s
@b = strong('Large').to_s
h1 "Monkeys"
h2 { "Giraffes #{@a} and #{@b}" }
h3 "Donkeys"
h4 { "Parakeet #{@b} as well..." }
}
It’s not needed in the above example, though, since the string interpolation will call to_s for you. Does that make sense?