I have created my own generator in the context of a plugin, and it worked
pretty well. There isn''t a functional difference between the two, so
maybe
you would be willing to go that route.
As I understand it, if you want to create a generator, you follow these
steps. Imagine the generator is going to be called "widget_generator"
1) Create the directory vendor/plugins/widget/generators/widget
2) Create the file
vendor/plugins/widget/generators/widget/widget_generator.rb
3) In that file, put this code:
class WidgetGenerator < Rails::Generator::Base
def manifest
record do |m|
### generator commands ...
end
end
end
Note all the file, directory and class names - they are very important. If
everything worked right, when you type "ruby script/generate" you
should see
"widget_generator" listed. Note that you can also inherit from
NamedBase and
you will get some command line argument support - though I haven''t
explored
that so I can''t speak to it.
Sadly, generators are pretty badly documented. I suggest browsing the Rails
source to see what you can do with them. In your gems installation, the
relevant files are in rails/lib/rails_generator.
If you want to look at a working generator, the plugin I mentioned above can
be downloaded from http://rubyforge.org/projects/realapps-cms/ . Just click
"Files" and get the latest zip. Unzip it into vendor/plugins and then
you
can run it with ''ruby script/generate realapps_cms''.
Hope that helps and good luck!
Justin
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060425/f88fa056/attachment.html