Writing HTML programmatically - Ramaze/ramaze GitHub Wiki

{Ramaze::Gestalt} is a utility class that can help you writing html programatically, so you don't have to "stuff" a String with HTML, or use here documents.

Here is the above code, revisited with Ramaze:Gestalt

def generate(current=nil)
  # Generate some HTML that will make create the side bar

  sidebar = Ramaze::Gestalt.new

  sidebar.div(:class =>"sd") do
    sidebar.h1 "This is a sidebar"
    sidebar.ul do
      sidebar.li "First item"
      sidebar.li "Second item"
    end
  end

  sidebar.to_s  
end

You can also use the Gestalt builder, which is a bit less verbose :

def generate(current=nil)
# Generate some HTML that will make the side bar

  sidebar = Ramaze::Gestalt.build do
    div(:class =>"sd") do
      h1 "This is a sidebar"
      ul do
        li "First item"
        li "Second item"
      end
    end
  end 
end