Need help with effigy?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

209 Stars 6 Forks MIT License 59 Commits 7 Opened issues


Ruby views without a templating language

Services available


Need anything else?

Contributors list

# 7,708
38 commits

h1. Effigy

Create usable views in Ruby with HTML and CSS selectors.

h2. Synopsis

In Effigy, your view is a Ruby class that performs transformation on an HTML template. The template is passed to a render method, which calls a private #transform method to apply the transformations. The transformed template is then returned as a string of HTML.

template = %{



There aren't any comments for this post.

} class PostView < Effigy::View attr_reader :post def initialize(post) @post = post end def transform text('h1', post.title) text('title', "#{post.title} - Site title") text('p.body', post.body) replace_each('.comment', post.comments) do |comment| text('h2', comment.title) text('p', comment.summary) attr('a', :href => url_for(comment)) end remove('#no-comments') if post.comments.any? end end view = document = view.render_html_document(template) # Result document: # # # Post title - Site title # # #

Post title


Post body


First comment title


First comment body

# View more #

Second comment title


Second comment body

# View more #
# #

See the documentation for more information on available transformations.

h2. Chaining

If you prefer, you can select elements and then apply tranformations in a chain. The previous example could have been written like this:

class PostView < Effigy::View
  attr_reader :post

  def initialize(post)
    @post = post

  def transform
    find('title').text("#{post.title} - Site title")
    find('.comment').replace_each(post.comments) do |comment|
      find('a').attr(:href => url_for(comment))
    find('#no-comments').remove if post.comments.any?

find is also aliased as #f for brevity, if you're into that sort of thing.

h2. Rails

Effigy integrates with Rails. It provides a view subclass that copies instance variables from the controller, a template handler to find Effigy views and templates, and a generator to create skeleton view files.


# app/controllers/magic_controller.rb
class MagicController < ApplicationController
  def index
    @spell = 'hocus pocus'
# app/views/magic/index.html.effigy
class MagicIndexView < Effigy::Rails::View
  def transform
    text('h1', @spell)
# app/templates/magic/index.html

Spell name goes here

View this example in your browser and you'll see "hocus pocus."

h2. Install

Effigy is distributed as a gem through gemcutter:

sudo gem install effigy -s

Effigy requires Nokogiri.

h2. Why?

Effigy is based on the idea that putting behavior in your templates is confusing and makes them difficult to maintain, and that the closer an ERB template gets to 50% Ruby, 50% HTML, the closer it gets to total chaos. Complicated views require unintuitive concepts (ERB buffers, capture blocks, etc). ERB also has the constant threat of unescaped user input slipping into a view.

Effigy was created because I have never liked interpolation-based templating languages like ERB and because XSLT requires introducing another language (and I like Ruby just fine).

h2. Author

Effigy was written by Joe Ferris. See LICENSE for license info.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.