-
Notifications
You must be signed in to change notification settings - Fork 526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ApplicationDecorator generator #796
ApplicationDecorator generator #796
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. I think it will be a nice addition.
I had a few minor comments, but we should be good to merge after that.
subject { file('app/decorators/application_decorator.rb') } | ||
|
||
describe 'naming' do | ||
before { run_generator %w(YourModels) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need the %w(YourModels)
here since this generator doesn't take any arguments.
# def percent_amount | ||
# h.number_to_percentage object.amount, precision: 2 | ||
# end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove empty line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@codebycliff, I was basing this template off of the decorator template. Do you want the two to match?
README.md
Outdated
@@ -155,6 +162,8 @@ rails generate decorator Article | |||
|
|||
...to create the `ArticleDecorator`. | |||
|
|||
Generated decorators will inherit from `Draper::Decorator` unless an `ApplicationDecorator` exists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be more in context to move this up with the rest of the new documentation. Something like:
To create an
ApplicationController
that all generated decorators inherit from, run:rails generate draper:install
I don't think the additional comment about them inheriting from Draper::Decorator
otherwise is necessary given that the paragraph above it says that all decorators inherit from Draper::Decorator
.
I could also see this documentation living in the "Installation" section of the README at some point. I think we should leave it here for now, but just something to think about.
describe 'the application decorator' do | ||
subject { file('app/decorators/application_decorator.rb') } | ||
|
||
describe 'naming' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need this block, do it?
@@ -0,0 +1,8 @@ | |||
class ApplicationDecorator < Draper::Decorator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed delegate_all
from this template. The belief is that certain issues and bad practices may stem from having this line in all decorators by default. Implementers should be encouraged to whitelist their delegations to minimize this risk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree completely. It's best not to assume functionality at the application level. I'd rather the user add this line themselves that way they are forced to understand what it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chuck-john @codebycliff
I agree your opinion too :)
However, how do you think about leaving as comment to notice function of delegate_all
? And additionally, if you agree with me, I want to add include Draper::LazyHelpers
as comment too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an interesting idea. If we left in any commented out stuff, I'd want to include all draper functionality that can be used (e.g. decorates_finders
) with documentation explaining. I think I'd like to wait for this though for the time being unless you feel strongly about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this. I'll go ahead and merge it unless anyone else has any comments.
I've added a bit comment. |
* Release 3.0.0 * Add breaking change #768 to changelog. * Add recently merged changes to the changelog. * Add configuration and custom default controller to the changelog. * Add entry to changelog for pull request 720 * Add entry to changelog for Rails 5 API-only support. * Add changelog entry for pull request #795. * Add changelog entry for pull request #796. * Add changelog entry for enumerable optimization. * Update maintainer information in README. * Add pull request #799 to changelog. * Add compatability documentation to readme.
Description
This branch introduces an installation generator. Running
rails generate draper:install
will create anApplicationDecorator
class, if none already exists. The purpose of this change is encourage use of the Rails'Application
naming convention by creating a parent decorator class from which others extend. Due to existing work, generated decorators will inherit fromApplicationDecorator
, if present. More information on this feature request can be found here.Testing
rails generate draper:install
in the dummy app.ApplicationDecorator
is created inapp/decorators/application_decorator.rb
.ApplicationDecorator
when present.To-Dos
N/A
References