hook in generator from controller generator
* use hook instead of invoke so it's easy to configure * hook into controller_generator and scaffold_controller_generator This feels more natural than invoking from the resource generator. Decorators are closely related to controllers, views and helpers. So they should be generated in that context. If controller generation is disabled for say generating resources there is no point in creating decorators.
This commit is contained in:
parent
0d388981fa
commit
cd4f298987
|
@ -6,7 +6,7 @@ module ActiveModel
|
|||
app ||= Rails.application # Rails 3.0.x does not yield `app`
|
||||
|
||||
Rails::Generators.configure! app.config.generators
|
||||
require_relative '../generators/resource_override'
|
||||
require_relative '../generators/controller_override'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
require "rails/generators"
|
||||
require "rails/generators/rails/controller/controller_generator"
|
||||
require "rails/generators/rails/scaffold_controller/scaffold_controller_generator"
|
||||
|
||||
module Rails
|
||||
module Generators
|
||||
|
||||
class ControllerGenerator
|
||||
hook_for :decorator, default: true
|
||||
end
|
||||
|
||||
class ScaffoldControllerGenerator
|
||||
hook_for :decorator, default: true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
require "rails/generators"
|
||||
require "rails/generators/rails/resource/resource_generator"
|
||||
|
||||
module Rails
|
||||
module Generators
|
||||
ResourceGenerator.class_eval do
|
||||
def add_decorator
|
||||
invoke "decorator"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
require 'rails'
|
||||
require 'ammeter/init'
|
||||
require 'generators/decorator/decorator_generator'
|
||||
require 'generators/rails/decorator_generator'
|
||||
|
||||
describe Rails::Generators::DecoratorGenerator do
|
||||
destination File.expand_path("../tmp", __FILE__)
|
||||
|
|
Loading…
Reference in New Issue