Skip to content
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

Merged
merged 26 commits into from
Apr 5, 2017
Merged

ApplicationDecorator generator #796

merged 26 commits into from
Apr 5, 2017

Conversation

chuck-john
Copy link
Contributor

@chuck-john chuck-john commented Apr 4, 2017

Description

This branch introduces an installation generator. Running rails generate draper:install will create an ApplicationDecorator 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 from ApplicationDecorator, if present. More information on this feature request can be found here.

Testing

  1. Run rails generate draper:install in the dummy app.
  2. Ensure the class ApplicationDecorator is created in app/decorators/application_decorator.rb.
  3. Ensure newly-generated decorators extend from ApplicationDecorator when present.

To-Dos

N/A

References

@chuck-john chuck-john changed the title installation generator ApplicationDecorator generator Apr 5, 2017
Copy link
Collaborator

@codebycliff codebycliff left a 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) }
Copy link
Collaborator

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty line.

Copy link
Contributor Author

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.
Copy link
Collaborator

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
Copy link
Contributor

@syguer syguer Apr 5, 2017

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
Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor

@syguer syguer Apr 5, 2017

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.

Copy link
Collaborator

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.

Copy link
Collaborator

@codebycliff codebycliff left a 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.

@syguer
Copy link
Contributor

syguer commented Apr 5, 2017

I've added a bit comment.
But great job. Patch looks good to me 👍

@codebycliff codebycliff merged commit a1d854a into drapergem:master Apr 5, 2017
codebycliff added a commit to codebycliff/draper that referenced this pull request Apr 5, 2017
@codebycliff codebycliff added this to the 3.0.0 milestone Apr 5, 2017
@chuck-john chuck-john deleted the feature/install-generator branch April 6, 2017 23:23
codebycliff added a commit that referenced this pull request May 8, 2017
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants