Skip to content

Commit

Permalink
Spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Hicks authored and josevalim committed Feb 2, 2010
1 parent f91c69b commit 8287cf6
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions README.rdoc
Expand Up @@ -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
Expand Down

0 comments on commit 8287cf6

Please sign in to comment.