<commit_before># Draper: View Models for Rails

[![TravisCI Build Status](https://secure.travis-ci.org/jcasimir/draper.png)](http://travis-ci.org/jcasimir/draper)
[![Gemnasium Build Status](https://gemnasium.com/jcasimir/draper.png)](https://gemnasium.com/jcasimir/draper)

## Quick Start

1. Add `gem 'draper'` to your `Gemfile` and `bundle`
2. Run `rails g draper:decorator YourModel`
3. Edit `app/decorators/[your_model]_decorator.rb` using:
  1. `h` to proxy to Rails/application helpers like `h.current_user`
  2. `[your_model]` to access the wrapped object like `article.created_at`
4. Wrap models in your controller with the decorator using:
  1. `.find` automatic lookup & wrap
    ex: `ArticleDecorator.find(1)`
  2. `.decorate` method with single object or collection, 
    ex: `ArticleDecorator.decorate(Article.all)`
  3. `.new` method with single object
    ex: `ArticleDecorator.new(Article.first)`
5. Output the instance methods in your view templates
  ex: `@article_decorator.created_at`

If you need common methods in your decorators, create an `app/decorators/application_decorator.rb`:

``` ruby
class ApplicationDecorator < Draper::Base
  # your methods go here
end
```

and make your decorators inherit from it. Newly generated decorators will respect this choice and inherit from `ApplicationDecorator`.

## Watch the RailsCast

<NAME> has put together an excellent RailsCast on Draper based on the 0.8.0 release:

[![RailsCast #286](https://img.skitch.com/20111021-dgxmqntq22d37fthky6pttk59n.jpg "RailsCast #286 - Draper")](http://railscasts.com/episodes/286-draper)

## What's New

Check out the full commit history at https://github.com/jcasimir/draper/compare/ad94f54369deabd11315fc241c66b74a30adec0a...04bb00505b7832419fddba20e5068317610eb38d<commit_msg>fixing generator names in README<commit_after># Draper: View Models for Rails

[![TravisCI Build Status](https://secure.travis-ci.org/jcasimir/draper.png)](http://travis-ci.org/jcasimir/draper)
[![Gemnasium Build Status](https://gemnasium.com/jcasimir/draper.png)](https://gemnasium.com/jcasimir/draper)

## Quick Start

1. Add `gem 'draper'` to your `Gemfile` and `bundle`
2. When you generate a resource with `rails g resource YourModel`, you get a decorator automatically!
3. If YourModel exists, run `rails g decorator YourModel`
4. Edit `app/decorators/[your_model]_decorator.rb` using:
  1. `h` to proxy to Rails/application helpers like `h.current_user`
  2. `[your_model]` to access the wrapped object like `article.created_at`
5. Wrap models in your controller with the decorator using:
  1. `.find` automatic lookup & wrap
    ex: `ArticleDecorator.find(1)`
  2. `.decorate` method with single object or collection, 
    ex: `ArticleDecorator.decorate(Article.all)`
  3. `.new` method with single object
    ex: `ArticleDecorator.new(Article.first)`
6. Output the instance methods in your view templates
  ex: `@article_decorator.created_at`

If you need common methods in your decorators, create an `app/decorators/application_decorator.rb`:

``` ruby
class ApplicationDecorator < Draper::Base
  # your methods go here
end
```

and make your decorators inherit from it. Newly generated decorators will respect this choice and inherit from `ApplicationDecorator`.

## Watch the RailsCast

<NAME> has put together an excellent RailsCast on Draper based on the 0.8.0 release:

[![RailsCast #286](https://img.skitch.com/20111021-dgxmqntq22d37fthky6pttk59n.jpg "RailsCast #286 - Draper")](http://railscasts.com/episodes/286-draper)

## What's New

Check out the full commit history at https://github.com/jcasimir/draper/compare/ad94f54369deabd11315fc241c66b74a30adec0a...04bb00505b7832419fddba20e5068317610eb38d
{'fraction_non_alphanumeric': 0.11165179778318464, 'fraction_numerical': 0.047850770478507706, 'mean_word_length': 5.035889070146819, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5167139', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1243, 'n_words': 356}