Project

exhibit

0.01
No commit activity in last 3 years
No release in over 3 years
Exhibit is a simple gem to generate and work with presenters in Rails 3. It is based on the solution Ryan Bates created in Railscasts Pro episode #287.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Exhibit

Exhibit is a simple gem to generate and work with presenters in Rails 3. It is based on the solution Ryan Bates created in Railscasts Pro episode #287.

version 0.1.5
Robin Brouwer
45north

Installation

Exhibit only works with Rails 3. Add the following to your Gemfile:

gem 'exhibit'

Now just run bundle install and you're ready to exhibit your application! ;)

Usage

Exhibit is a simple and lightweight gem. Using it is pretty straightforward. Run the following generator to create a presenter:

rails g exhibit:presenter User

The presenter is stored in app/presenters/user_presenter.rb.

class UserPresenter < Exhibit::Presenter
  exhibit :user
end

You can add methods to this class to exhibit content.

class UserPresenter < Exhibit::Presenter
  exhibit :user
  
  def email
    content_tag(:span, user.email)
  end
end

You can also use delegate to delegate methods to the User Model.

class UserPresenter < Exhibit::Presenter
  exhibit :user
  delegate :email, :to => :user
end

Want to add methods that can be used inside all of your presenters? Run the following command:

rails g exhibit:base

A new initializer will be created: config/initializers/exhibit_presenter.rb. You can add methods to this class to extend it and use it inside all presenters.

But how can you actually use presenters inside the view? It works the same as Ryan shows you in Railscasts Pro episode #287:

<% exhibit(@user) do |user| %>
  <p>
    <strong>E-mail:</strong>
    <%= user.email %>
  </p>
<% end %>

Got feedback? Feature requests? Add it as an issue or create a pull request. Have fun exhibiting your application!