Permalink
Browse files

Spacing

  • Loading branch information...
1 parent f91c69b commit 8287cf617c710a5e49f99d38f5f4e37f0114586b Jonathan Hicks committed with josevalim Feb 2, 2010
Showing with 31 additions and 31 deletions.
  1. +31 −31 README.rdoc
View
62 README.rdoc
@@ -234,44 +234,44 @@ 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 <tt>thor -T</tt> will show how to run our generator. It should read:
<tt>thor newgem_generator NAME</tt>. This shows that we have to supply a NAME
argument for our generator to run.
The <tt>create_lib_file</tt> 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 <tt>template</tt> gets called. Be sure to read the documentation[http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor/Actions.html] for

0 comments on commit 8287cf6

Please sign in to comment.