Rails 3: app template example?
I'd like to see an example of an application generator template for Rails 3. Any suggestions?
I'm interested in an example of a template that is used to generate a new Rails application. Ryan Bates has a screencast (#148 App Templates in Rails 2开发者_如何学运维.3) that describes how to create an application generator template for Rails 2.3 but I'd like to see how something similar is implemented in Rails 3. I've seen several tutorials on using the Rails 3 generators but I haven't found anything that shows how to create an application generator template.
I presume all of the capabilities of Thor and Rails::Generators::Actions are available but I'd like to see how to use them in an application generator template.
It seems terminology is confusing here. "View Template Engines" (such as Haml) are one thing; "Rails Generators" (such as used for "rails generate helper") are another thing; and "Application Generator Templates" (used for "rails new app_name -m some/path/to/template") are quite another thing.
Dug around in the Rails source and answered this question myself :-)
Here's an example of an application generator template for Rails 3:
http://github.com/fortuity/rails3-mongoid-devise/raw/master/template.rb
Usage:
rails new app_name -m http://github.com/fortuity/rails3-mongoid-devise/raw/master/template.rb
In customizing this template, you can use any methods provided by Thor::Actions
http://rdoc.info/rdoc/wycats/thor/blob/f939a3e8a854616784cac1dcff04ef4f3ee5f7ff/Thor/Actions.html
and Rails::Generators::Actions
http://github.com/rails/rails/blob/master/railties/lib/rails/generators/actions.rb
精彩评论