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

Merge pull request #553 from azul/hook-generator-in-controller-generator

hook generator from controller generator
This commit is contained in:
Steve Klabnik 2013-06-10 19:51:46 -07:00
commit 8a63ca0de6
7 changed files with 19 additions and 15 deletions

View file

@ -131,11 +131,12 @@ end
### Generators
When you have Draper installed and generate a resource with...
When you have Draper installed and generate a controller for example with...
```
rails generate resource Article
```
...you'll get a decorator for free!
But if the `Article` model already exists, you can run...

View file

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

View file

@ -0,0 +1,15 @@
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 '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__)