Web pages are created using a variety of technologies; the most popular is HyperText Markup Language (HTML). HTML is a language that can be represented in plain text and is composed of numerous tags that indicate the meaning of each part of the document.
For example:

<html>
  <head>
    <title>This is the title</title>
  </head>
  <body>
    <p>This is a paragraph</p>
  </body>
</html>

Markaby—Markup As Ruby
Markaby is a library developed by Tim Fletcher (http://tfletcher.com/) and “why the lucky stiff” (http://whytheluckystiff.net/) that allows you to create HTML by using Ruby methods and structures. Markaby is distributed as a gem, so it’s trivial to install using the gem client, like so:

gem install markaby

Once Markaby is installed, the following example should demonstrate the basic principles of generating HTML with it:

require 'rubygems'
require 'markaby'
m = Markaby::Builder.new
m.html do
  head { title 'This is the title' }
  body do
    h1 'Hello world'
    h2 'Sub-heading'
    p %q{This is a pile of stuff showing off Markaby's features}
    h2 'Another sub-heading'
    p 'Markaby is good at:'
    ul do
       li 'Generating HTML from Ruby'
       li 'Keeping HTML structured'
       li 'Lots more..'
    end
  end
end
puts m

Advertisements