Props - Nokogiri's Builder notation has class and ID shortcuts

P

Phlip

Rubies:

This is just a note to document a nice discovery in Nokogiri's tests:

builder = Nokogiri::HTML::Builder.new do
div.rad.thing! {
text "<awesome>"
b "hello"
}
end
assert_equal(
'<div class="rad" id="thing">&lt;awesome&gt;<b>hello</b></div>',
builder.doc.root.to_html.gsub(/\n/, ''))

The Builder notation div.rad.thing! expanded to <div class="rad" id="thing">.
This implies .rad, without a bang, expands to class="rad", and .thing!, with the
bang, expands to an ID.

(-8
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top