提交 d5bdf31d 编写于 作者: J José Valim

Refactoring out descriptions.

上级 6e6c0117
......@@ -15,16 +15,27 @@ def self.source_root
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), base_name, generator_name, 'templates'))
end
# Tries to get the description from a USAGE file one folder above the source
# root otherwise uses a default description.
#
def self.desc(description=nil)
return super if description
usage = File.join(source_root, "..", "USAGE")
@desc ||= if File.exist?(usage)
File.read(usage)
else
"Description:\n Create #{base_name.humanize.downcase} files for #{generator_name} generator."
end
end
# Convenience method to get the namespace from the class name. It's the
# same as Thor default except that the Generator at the end of the class
# is removed.
#
def self.namespace(name=nil) #:nodoc:
if name
super
else
@namespace ||= "#{base_name}:generators:#{generator_name}"
end
def self.namespace(name=nil)
return super if name
@namespace ||= "#{base_name}:generators:#{generator_name}"
end
protected
......@@ -70,7 +81,7 @@ def self.banner
# Sets the base_name taking into account the current class namespace.
#
def self.base_name #:nodoc:
def self.base_name
@base_name ||= self.name.split('::').first.underscore
end
......
......@@ -3,11 +3,6 @@ module Generators
class MailerGenerator < Base
argument :actions, :type => :array, :default => []
desc <<DESC
Description:
Create Template engine files for mailer generator.
DESC
def create_view_files
actions.each do |action|
@action, @path = action, File.join(file_path, action)
......
......@@ -3,11 +3,6 @@ module Generators
class MailerGenerator < Base
argument :actions, :type => :array, :default => []
desc <<DESC
Description:
Create TestUnit files for mailer generator.
DESC
def create_test_files
template "unit_test.rb", File.join('test', 'unit', class_path, "#{file_name}_test.rb")
end
......
module TestUnit
module Generators
class ObserverGenerator < Base
desc <<DESC
Description:
Create TestUnit files for observer generator.
DESC
def create_test_files
template 'unit_test.rb', File.join('test', 'unit', class_path, "#{file_name}_observer_test.rb")
end
......
module TestUnit
module Generators
class PluginGenerator < Base
desc <<DESC
Description:
Create TestUnit files for plugin generator.
DESC
def create_test_files
directory 'test'
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册