How to create a Generator (Component Generator)
¶ ↑
-
DONE - Run the generator: script/generate component_generator mygen
-
Using the generated test class, assert what directories, files, classes etc should be generated.
-
Add these files into the *scope*_generators/mygen/templates folder. Your files can use ERb (that is, <%= … %>), and are called 'templates'.
-
Specify who the files in /templates are copied/templated at generation time within app_generators/mygen/mygen_generators.rb 's manifest method.
* Use m.file for files to copy over. * Use m.template for files containing ERb. Create attr_reader accessors for any variables your templates need access to.
-
Run unit tests.
-
Add usage information in the USAGE file.
-
Update your Manifest.txt with the new files (if you are using Hoe)
-
Build and install your RubyGem locally. Run: rake install_gem
-
Go to a work area whose script/generate for your scope (e.g. go to the root folder of a Rails application to use a 'rails' scoped generator.
-
Run “script/generate” and your new generator should appear in the list of available generators.
-
Run “script/generate mygen” to see the options and usage information for your generator.
-
Run “script/generator mygen arguments” to execute the generator.
-
Done.
See this message again using the -h/–help option.