mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Update README and generator templates to use lazy_helpers and draper:decorator
This commit is contained in:
parent
56d2b7a118
commit
fc606e1d56
3 changed files with 9 additions and 8 deletions
|
@ -3,7 +3,7 @@
|
|||
## Quick Start
|
||||
|
||||
1. Add `gem 'draper'` to your `Gemfile` and `bundle`
|
||||
2. Run `rails g draper:model YourModel`
|
||||
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. `model` to access the wrapped object like `model.created_at`
|
||||
|
@ -143,7 +143,7 @@ If you want a helper, you can still call `rails generate helper` directly.
|
|||
To decorate a model named `Article`:
|
||||
|
||||
```
|
||||
rails generate draper:model Article
|
||||
rails generate draper:decorator Article
|
||||
```
|
||||
|
||||
### Writing Methods
|
||||
|
@ -183,7 +183,7 @@ Hate seeing that `h.` proxy all over? Willing to mix a bazillion methods into yo
|
|||
```ruby
|
||||
class ArticleDecorator < ApplicationDecorator
|
||||
decorates :article
|
||||
include Draper::LazyHelpers
|
||||
lazy_helpers
|
||||
|
||||
def published_at
|
||||
date = content_tag(:span, model.published_at.strftime("%A, %B %e").squeeze(" "), :class => 'date')
|
||||
|
@ -250,7 +250,7 @@ First, follow the steps above to add the dependency and update your bundle.
|
|||
Since we're talking about the `Article` model we'll create an `ArticleDecorator` class. You could do it by hand, but use the provided generator:
|
||||
|
||||
```
|
||||
rails generate draper:model Article
|
||||
rails generate draper:decorator Article
|
||||
```
|
||||
|
||||
Now open up the created `app/decorators/article_decorator.rb` and you'll find an `ArticleDecorator` class. Add this method:
|
||||
|
@ -297,6 +297,8 @@ end
|
|||
|
||||
* Documentation
|
||||
* Keep revising Readme for better organization/clarity
|
||||
* Add more information about using "context"
|
||||
* Add information about the `.decorator` method
|
||||
* Make clear the pattern of overriding accessor methods of the wrapped model
|
||||
* Build sample Rails application(s)
|
||||
* Add a short screencast
|
||||
|
@ -305,7 +307,6 @@ end
|
|||
* Generators
|
||||
* Test coverage for generators (help!)
|
||||
* Implement hook so generating a controller/scaffold generates a decorator
|
||||
* Refactor the current generator from `draper:model` to `draper:decorator`
|
||||
* Add generators for...
|
||||
* `draper:model`: Model + Decorator
|
||||
* `draper:controller`: Controller setup with decoration calls
|
||||
|
|
|
@ -6,7 +6,7 @@ class ApplicationDecorator < Draper::Base
|
|||
# and probably sacrifice performance/memory
|
||||
#
|
||||
# Enable them by uncommenting this line:
|
||||
# include Draper::LazyHelpers
|
||||
# lazy_helpers
|
||||
|
||||
# Shared Decorations
|
||||
# Consider defining shared methods common to all your models.
|
||||
|
|
|
@ -7,8 +7,8 @@ class <%= singular_name.camelize %>Decorator < ApplicationDecorator
|
|||
# Normal Usage: helpers.number_to_currency(2)
|
||||
# Abbreviated : h.number_to_currency(2)
|
||||
#
|
||||
# Or, optionally enable "lazy helpers" by including this module:
|
||||
# include Draper::LazyHelpers
|
||||
# Or, optionally enable "lazy helpers" by calling this method:
|
||||
# lazy_helpers
|
||||
# Then use the helpers with no proxy:
|
||||
# number_to_currency(2)
|
||||
|
||||
|
|
Loading…
Reference in a new issue