diff --git a/README.rdoc b/README.rdoc index 9e694741a..36c88fcf9 100644 --- a/README.rdoc +++ b/README.rdoc @@ -234,35 +234,35 @@ placed. Be sure to check the documentation on actions[http://rdoc.info/rdoc/wyca A great use for Thor is creating custom generators. Combining Thor::Group, Thor::Actions and ERB templates makes this very easy. Here is an example: - class NewgemGenerator < Thor::Group - include Thor::Actions - - # Define arguments and options - argument :name - class_option :test_framework, :default => :test_unit - - def self.source_root - File.dirname(__FILE__) - end - - def create_lib_file - template('templates/newgem.tt', "#{name}/lib/#{name}.rb") - end - - def create_test_file - test = options[:test_framework] == "rspec" ? :spec : :test - create_file "#{name}/#{test}/#{name}_#{test}.rb" - end - - def copy_licence - if yes? "Use MIT license?" - # Make a copy of the MITLICENSE file at the source root - copy_file "MITLICENSE", "#{name}/MITLICENSE" - else - say "Shame on you…", :red - end - end - end + class NewgemGenerator < Thor::Group + include Thor::Actions + + # Define arguments and options + argument :name + class_option :test_framework, :default => :test_unit + + def self.source_root + File.dirname(__FILE__) + end + + def create_lib_file + template('templates/newgem.tt', "#{name}/lib/#{name}.rb") + end + + def create_test_file + test = options[:test_framework] == "rspec" ? :spec : :test + create_file "#{name}/#{test}/#{name}_#{test}.rb" + end + + def copy_licence + if yes? "Use MIT license?" + # Make a copy of the MITLICENSE file at the source root + copy_file "MITLICENSE", "#{name}/MITLICENSE" + else + say "Shame on you…", :red + end + end + end Doing a thor -T will show how to run our generator. It should read: thor newgem_generator NAME. This shows that we have to supply a NAME @@ -270,8 +270,8 @@ argument for our generator to run. The create_lib_file uses an ERB template. This is what it looks like: - class <%= name.camelize %> - end + class <%= name.camelize %> + end The arguments that you set in your generator will automatically be passed in when template gets called. Be sure to read the documentation[http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor/Actions.html] for