This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
Nicolas Mérouze (author)
Fri Jun 06 03:29:38 -0700 2008
commit fb8f45b8a536f74f5f9bf3f9a68abfdfc1cc802e
tree bcfd5778a49e1312705e5f5d1110c1159a2e89ea
parent f9582b5c4d15f97236698bf1c331840a0c637826
tree bcfd5778a49e1312705e5f5d1110c1159a2e89ea
parent f9582b5c4d15f97236698bf1c331840a0c637826
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Fri Jun 06 03:29:38 -0700 2008 | [Nicolas Mérouze] |
| |
CHANGELOG | Fri Jun 06 03:29:38 -0700 2008 | [Nicolas Mérouze] |
| |
MIT-LICENSE | Sun May 04 10:59:14 -0700 2008 | [Nicolas Mérouze] |
| |
README.rdoc | Fri Jun 06 03:29:38 -0700 2008 | [Nicolas Mérouze] |
| |
init.rb | Fri Jun 06 03:29:38 -0700 2008 | [Nicolas Mérouze] |
| |
lib/ | Fri Jun 06 03:29:38 -0700 2008 | [Nicolas Mérouze] |
| |
spec/ | Fri Jun 06 03:29:38 -0700 2008 | [Nicolas Mérouze] |
README.rdoc
Action Presenter
Inspired by : http://www.caboo.se/articles/2007/8/23/simple-presenters
Requirements
- Rails 2.1 and later.
Install
ruby script/plugin install git://github.com/nmerouze/action_presenter.git
Usage
Here’s a presenter :
class ArticlePresenter < ActionPresenter::Base
def title
h @source.title
end
end
And to call it in the views, there are present() and p() :
<%= present(@article).title %> or <%= p(@article).title %>
Instead of a tradionnal loop or iterator, you can use present() :
<% present(@articles) do |article| %>
<h2><%= article.title %></h2>
<% end %>
If you want to use methods from the source record inside the iterator (or somewhere else), you just have to use source() or s() :
<% present(@articles) do |article| %>
<h2><%= h source(article).title %></h2>
<% end %>
Render files
You can also render files for a presenter method :
class ArticlePresenter < ActionPresenter::Base
def title
render :title
end
def body
render :body, :msg => 'Hello World!'
end
end
The partial for title will be located in app/presenters/article/title.html.erb :
<%=h article.title %>
The partial for body will be located in app/presenters/article/body.html.erb :
<%= article.body + msg %>
Presenters in your plugins
You can have presenters in plugins. Just create a directory app/presenters and you’re ready to go. It’s great if you have Engines too.
Contact
nicolas.merouze (at) gmail (dot) com




