From f1bd79b71d8aaf2659e159c897337ffa89398617 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 11 May 2012 18:58:38 -0300 Subject: [PATCH] Updating README. Thanks @beerlington! --- Readme.markdown | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/Readme.markdown b/Readme.markdown index 56df758..0209dd2 100644 --- a/Readme.markdown +++ b/Readme.markdown @@ -155,20 +155,12 @@ gem "draper" Then run `bundle` from the project directory. -### Run the draper:install command - -This will create the `app/decorators` directory and the `ApplicationDecorator` inside it. - -``` -rails generate draper:install -``` - ### Generate the Decorator To decorate a model named `Article`: ``` -rails generate draper:decorator article +rails generate decorator article ``` ### Writing Methods @@ -176,7 +168,7 @@ rails generate draper:decorator article Open the decorator model (ex: `app/decorators/article_decorator.rb`) and add normal instance methods. To access the wrapped source object, use a method named after the `decorates` argument: ```ruby -class ArticleDecorator < ApplicationDecorator +class ArticleDecorator < Draper::Base decorates :article def author_name @@ -190,7 +182,7 @@ end You probably want to make use of Rails helpers and those defined in your application. Use the `helpers` or `h` method proxy: ```ruby -class ArticleDecorator < ApplicationDecorator +class ArticleDecorator < Draper::Base decorates :article def published_at @@ -206,7 +198,7 @@ end Hate seeing that `h.` proxy all over? Willing to mix a bazillion methods into your decorator? Then try lazy helpers: ```ruby -class ArticleDecorator < ApplicationDecorator +class ArticleDecorator < Draper::Base decorates :article include Draper::LazyHelpers @@ -313,7 +305,7 @@ end Then you need to perform the wrapping in your controller. Here's the simplest method: ```ruby -class ArticlesController < ApplicationController +class ArticlesController < Draper::Decorator def show @article = ArticleDecorator.find params[:id] end @@ -329,7 +321,7 @@ Then within your views you can utilize both the normal data methods and your new Ta-da! Object-oriented data formatting for your view layer. Below is the complete decorator with extra comments removed: ```ruby -class ArticleDecorator < ApplicationDecorator +class ArticleDecorator < Draper::Base decorates :article def published_at @@ -345,12 +337,12 @@ end Add a `decorates_association :association_name` to gain access to a decorated version of your target association. ```ruby -class ArticleDecorator < ApplicationDecorator +class ArticleDecorator < Draper::Base decorates :article decorates_association :author # belongs_to :author association end -class AuthorDecorator < ApplicationDecorator +class AuthorDecorator < Draper::Base decorates :author def fancy_name