mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Added callback to the generator to enable chaining
This commit is contained in:
parent
00cec639c0
commit
94ecaaf643
2 changed files with 17 additions and 4 deletions
|
@ -138,16 +138,19 @@ end
|
|||
If you want a helper, you can still call `rails generate helper` directly.
|
||||
|
||||
|
||||
#### Replace Rails Helper Generation with Decorator Generation (Optional)
|
||||
#### Add DecoratorGenerator to ActiveRecord Generator (Optional)
|
||||
|
||||
If you want to completely replace the helper generation with the decorator generator, just add this to your `config/application.rb`
|
||||
Add the following to your `config/application.rb`
|
||||
|
||||
```ruby
|
||||
config.generators do |g|
|
||||
g.helper :decorator
|
||||
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`:
|
||||
|
|
|
@ -2,4 +2,14 @@ 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