2012-05-09 17:32:58 +00:00
|
|
|
module Rails
|
|
|
|
module Generators
|
|
|
|
class DecoratorGenerator < NamedBase
|
|
|
|
source_root File.expand_path("../templates", __FILE__)
|
|
|
|
check_class_collision :suffix => "Decorator"
|
|
|
|
|
|
|
|
class_option :parent, :type => :string, :desc => "The parent class for the generated decorator"
|
|
|
|
|
|
|
|
def create_decorator_file
|
|
|
|
template 'decorator.rb', File.join('app/decorators', class_path, "#{file_name}_decorator.rb")
|
|
|
|
end
|
|
|
|
|
|
|
|
hook_for :test_framework
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def parent_class_name
|
|
|
|
if options[:parent]
|
|
|
|
options[:parent]
|
2012-05-11 23:17:12 +00:00
|
|
|
elsif defined?(ApplicationDecorator)
|
2012-05-09 17:32:58 +00:00
|
|
|
"ApplicationDecorator"
|
|
|
|
else
|
2012-10-09 08:51:40 +00:00
|
|
|
"Draper::Decorator"
|
2012-05-09 17:32:58 +00:00
|
|
|
end
|
|
|
|
end
|
2012-12-03 22:51:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Rails 3.0.X compatibility, stolen from https://github.com/jnunemaker/mongomapper/pull/385/files#L1R32
|
|
|
|
unless methods.include?(:module_namespacing)
|
|
|
|
def module_namespacing(&block)
|
|
|
|
yield if block
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-05-09 17:32:58 +00:00
|
|
|
end
|
|
|
|
end
|