1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

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:
Azul 2013-06-07 21:34:02 +02:00
parent 0d388981fa
commit cd4f298987
6 changed files with 19 additions and 14 deletions

View file

@ -6,7 +6,7 @@ module ActiveModel
app ||= Rails.application # Rails 3.0.x does not yield `app` app ||= Rails.application # Rails 3.0.x does not yield `app`
Rails::Generators.configure! app.config.generators Rails::Generators.configure! app.config.generators
require_relative '../generators/resource_override' require_relative '../generators/controller_override'
end end
end end
end end

View file

@ -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

View file

@ -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

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
require 'rails' require 'rails'
require 'ammeter/init' require 'ammeter/init'
require 'generators/decorator/decorator_generator' require 'generators/rails/decorator_generator'
describe Rails::Generators::DecoratorGenerator do describe Rails::Generators::DecoratorGenerator do
destination File.expand_path("../tmp", __FILE__) destination File.expand_path("../tmp", __FILE__)