-
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
Merged
codebycliff
merged 26 commits into
drapergem:master
from
chuck-john:feature/install-generator
Apr 5, 2017
+48
−8
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b66e34c
un-skip test and remove unused class definition
180ee28
fix build
0dbf6de
Merge branch 'draper/master'
d25d42e
Merge branch 'draper/master'
b48361c
Merge branch 'draper/master'
21d7035
add InstallGenerator
b89e781
re-namespace generators
a556bbb
Merge branch 'draper/master'
61be5a0
Merge branch 'master' into feature/install-generator
11589fd
remove module namespacing
41abfe9
update README with new generator command
d6a3f87
Merge branch 'draper/master'
7614c9b
Merge branch 'master' into feature/install-generator
e16bf4d
inherit from Base instead of NamedBase
06b2527
add inheritance line to Generators section of README
ef6eb61
call #copy_file instead of #template
e7cbc49
remove skip functionality
4b145b4
refactor once-used variable
7b21a6d
specify application_decorator.rb file instead of class
f0d03ad
move decorator generator back to rails namespace
fa6c9ce
revert README change
1f165e6
specify decorator class
bd76ae6
re-word template help text
161717e
remove unnecessary describe block
511993f
remove delegate_all from application_decorator template
6196073
edit README
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Draper | ||
module Generators | ||
class InstallGenerator < Rails::Generators::Base | ||
source_root File.expand_path('../templates', __FILE__) | ||
|
||
desc 'Creates an ApplicationDecorator, if none exists.' | ||
|
||
def create_application_decorator | ||
file = 'application_decorator.rb' | ||
copy_file file, "app/decorators/#{file}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class ApplicationDecorator < Draper::Decorator | ||
# Define methods for all decorated objects. | ||
# Helpers are accessed through `helpers` (aka `h`). For example: | ||
# | ||
# def percent_amount | ||
# h.number_to_percentage object.amount, precision: 2 | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'spec_helper' | ||
require 'dummy/config/environment' | ||
require 'ammeter/init' | ||
require 'generators/draper/install_generator' | ||
|
||
describe Draper::Generators::InstallGenerator do | ||
destination File.expand_path('../tmp', __FILE__) | ||
|
||
before { prepare_destination } | ||
after(:all) { FileUtils.rm_rf destination_root } | ||
|
||
describe 'the application decorator' do | ||
subject { file('app/decorators/application_decorator.rb') } | ||
|
||
before { run_generator } | ||
|
||
it { is_expected.to contain 'class ApplicationDecorator' } | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 addinclude 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.