mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Merge pull request #24 from apauly/master
Replacing hooks in config object
This commit is contained in:
commit
1cb1696490
2 changed files with 29 additions and 1 deletions
|
@ -135,9 +135,22 @@ config.generators do |g|
|
|||
g.helper false
|
||||
end
|
||||
```
|
||||
|
||||
If you want a helper, you can still call `rails generate helper` directly.
|
||||
|
||||
|
||||
#### Add DecoratorGenerator to ActiveRecord Generator (Optional)
|
||||
|
||||
Add the following to your `config/application.rb`
|
||||
|
||||
```ruby
|
||||
config.generators do |g|
|
||||
g.orm :decorator, :invoke_after_finished => "active_record:model"
|
||||
end
|
||||
```
|
||||
|
||||
From now on, every model you generate will first invoke the DecoratorGenerator. The Decorator will then invoke the active_record:model Generator.
|
||||
|
||||
|
||||
### Generate the Decorator
|
||||
|
||||
To decorate a model named `Article`:
|
||||
|
|
15
lib/generators/rails/decorator_generator.rb
Normal file
15
lib/generators/rails/decorator_generator.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require File.expand_path('../../draper/decorator/decorator_generator.rb', __FILE__)
|
||||
class Rails::DecoratorGenerator < Draper::DecoratorGenerator
|
||||
|
||||
source_root File.expand_path('../../draper/decorator/templates', __FILE__)
|
||||
|
||||
class_option :invoke_after_finished, :type => :string, :description => "Generator to invoke when finished"
|
||||
|
||||
def build_model_and_application_decorators
|
||||
super
|
||||
if self.options[:invoke_after_finished]
|
||||
Rails::Generators.invoke(self.options[:invoke_after_finished], [@name, @_initializer.first[1..-1]])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue