require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb") class MondoAuthenticationGenerator < Rails::Generator::Base attr_accessor :user_name, :session_name def initialize(runtime_args, runtime_options = {}) super @user_name = @args[0] || 'user' @session_name = @args[1] || 'user_session' end def manifest record do |m| m.directory "app/models" m.directory "app/controllers" m.directory "app/helpers" m.directory "app/views" m.directory "lib" m.directory "app/views/static_pages" m.template "static_pages_controller.rb", "app/controllers/static_pages_controller.rb" m.template "views/home.html.haml", "app/views/static_pages/home.html.haml" m.directory "app/views/#{user_plural_name}" m.template "user.rb", "app/models/#{user_singular_name}.rb" m.template "users_controller.rb", "app/controllers/#{user_plural_name}_controller.rb" m.template "users_helper.rb", "app/helpers/#{user_plural_name}_helper.rb" m.template "views/new.html.haml", "app/views/#{user_plural_name}/new.html.haml" m.template "views/edit.html.haml", "app/views/#{user_plural_name}/edit.html.haml" m.template "views/_form.html.haml", "app/views/#{user_plural_name}/_form.html.haml" m.template "views/show.html.haml", "app/views/#{user_plural_name}/show.html.haml" m.template "views/index.html.haml", "app/views/#{user_plural_name}/index.html.haml" m.template "views/mass_new.html.haml", "app/views/#{user_plural_name}/mass_new.html.haml" m.directory "app/views/#{session_plural_name}" m.template "session.rb", "app/models/#{user_singular_name}_session.rb" m.template "sessions_controller.rb", "app/controllers/#{session_plural_name}_controller.rb" m.template "views/login.html.haml", "app/views/#{session_plural_name}/new.html.haml" m.template "authentication.rb", "lib/authentication.rb" m.template "authorization_rules.rb", "config/authorization_rules.rb" m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{user_plural_name}" m.route_name :signup, '/signup', :controller => user_plural_name, :action => 'new' m.route_name :logout, '/logout', :controller => session_plural_name, :action => 'destroy' m.route_name :login, '/login', :controller => session_plural_name, :action => 'new' m.route_root :controller => 'static_pages', :action => 'home' m.route_resources session_plural_name m.route_resource_with_options user_plural_name, :collections => ':mass_new => :get, :mass_create => :post' m.insert_into "app/controllers/#{application_controller_name}.rb", 'include Authentication' m.template "locales/en.yml", "config/locales/en.yml" m.template "locales/it.yml", "config/locales/it.yml" end end def user_singular_name user_name.underscore end def user_plural_name user_singular_name.pluralize end def user_class_name user_name.camelize end def user_plural_class_name user_plural_name.camelize end def session_singular_name session_name.underscore end def session_plural_name session_singular_name.pluralize end def session_class_name session_name.camelize end def session_plural_class_name session_plural_name.camelize end def application_controller_name Rails.version >= '2.3.0' ? 'application_controller' : 'application' end protected def add_options!(opt) opt.separator '' opt.separator 'Options:' end def banner <<-EOS Creates user model and controllers to handle registration and authentication. USAGE: #{$0} [user_name] [sessions_controller_name] EOS end end