Fork me on GitHub

Erector is a Builder-like view framework for Ruby, inspired by Markaby.

In Erector all views are objects, not template files, which allows the full power of object-oriented programming (inheritance, modular decomposition, encapsulation) in views.

Examples

require 'erector'

class Hello < Erector::Widget
  def content
    html {
      head {
        title "Hello"
      }
      body {
        h1.heading! "Message:"
        text "Hello, "
        b.big @target
        text "!"
      }
    }
  end
end

Hello.new(:target => 'world').to_html
<html>
  <head>
    <title>Hello</title>
  </head>
  <body>
    <h1 id="heading">Message:</h1>
    Hello, <b class="big">world</b>!
  </body>
</html>
include Erector::Mixin
erector { div "love", :class => "big" }
<div class="big">love</div>
require 'erector'
class Logo < Erector::Widget
  def content
    div.logo {
      a(:href => "index.html") {
        img.logo :src => 'erector.jpg',
          :height => 323, 
          :width => 287
      }
    }
  end
end
<div class="logo">
  <a href="index.html">
    <img class="logo" height="323" 
      src="erector.jpg" width="287" />
  </a>
</div>

Current version: 0.9.0