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


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

     builder = do
       div.rad.thing! {
         text "<awesome>"
         b "hello"
       '<div class="rad" 

builder.doc.root.to_html.gsub(/\n/, ‘’))

The Builder notation div.rad.thing! expanded to

This implies .rad, without a bang, expands to class=“rad”, and .thing!,
with the
bang, expands to an ID.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs