public
Description: Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser with XPath and CSS selector support.
Home | Edit | New

Generate

require 'rubygems'
require 'nokogiri'

@builder = Nokogiri::HTML::Builder.new do |doc|
  doc.html {
    doc.head {
      doc.script {
        doc.text "alert('hello world');"
      }
      doc.style {
        doc.text "div#thing { background: red; }"
      }
      doc.title "Awesome Page" 
    }
    doc.body {
      doc.div.rad.thing! {
        doc.h1 "This is an h1"
        doc.text "This is a div with class 'rad' and id 'thing'"

        doc.div( :some_attribute => 'foo' ) {
          doc.p "This is an awesome paragraph!"
        }
      }
    }
  }
end

puts @builder.to_html
Last edited by vazqujav, Wed Apr 22 16:19:54 -0700 2009
Home | Edit | New
Versions: