Module: Rails::Generator
- Defined in:
- lib/rails_generator/base.rb,
lib/rails_generator/spec.rb,
lib/rails_generator/options.rb,
lib/rails_generator/scripts.rb,
lib/rails_generator/commands.rb,
lib/rails_generator/manifest.rb,
lib/rails_generator/simple_logger.rb,
lib/rails_generator/generated_attribute.rb,
lib/rails_generator/lookup.rb
Overview
Rails::Generator is a code generation platform tailored for the Rails web application framework. Generators are easily invoked within Rails applications to add and remove components such as models and controllers. New generators are easy to create and may be distributed as RubyGems, tarballs, or Rails plugins for inclusion system-wide, per-user, or per-application.
For actual examples see the rails_generator/generators directory in the
Rails source (or the railties directory if you have frozen the Rails
source in your application).
Generators may subclass other generators to provide variations that require little or no new logic but replace the template files.
For a RubyGem, put your generator class and templates in the lib
directory. For a Rails plugin, make a generators directory at the
root of your plugin.
The layout of generator files can be seen in the built-in
controller generator:
generators/
components/
controller/
controller_generator.rb
templates/
controller.rb
functional_test.rb
helper.rb
view.html.erb
The directory name (+controller+) matches the name of the generator file
(controller_generator.rb) and class (ControllerGenerator). The files
that will be copied or used as templates are stored in the templates
directory.
The filenames of the templates don't matter, but choose something that
will be self-explanatory since you will be referencing these in the
manifest method inside your generator subclass.
Defined Under Namespace
Modules: Commands, Lookup, Options, Scripts Classes: AbstractGemSource, Base, GemGeneratorSource, GemPathSource, GeneratedAttribute, GeneratorError, Manifest, NamedBase, PathSource, SimpleLogger, Source, Spec, UsageError