diff options
Diffstat (limited to 'railties/lib/rails/generators')
8 files changed, 31 insertions, 74 deletions
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index 0da85ea4a4..766644bbc2 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -20,24 +20,19 @@ module Rails add_runtime_options! - # Automatically sets the source root based on the class name. - # - def self.source_root - @_rails_source_root ||= begin - if base_name && generator_name - File.expand_path(File.join(base_name, generator_name, 'templates'), File.dirname(__FILE__)) - end - end + # Returns the source root for this generator using default_source_root as default. + def self.source_root(path=nil) + @_source_root = path if path + @_source_root ||= default_source_root end # Tries to get the description from a USAGE file one folder above the source # root otherwise uses a default description. - # def self.desc(description=nil) return super if description - usage = File.expand_path(File.join(source_root, "..", "USAGE")) + usage = source_root && File.expand_path("../USAGE", source_root) - @desc ||= if File.exist?(usage) + @desc ||= if usage && File.exist?(usage) File.read(usage) else "Description:\n Create #{base_name.humanize.downcase} files for #{generator_name} generator." @@ -47,7 +42,6 @@ module Rails # Convenience method to get the namespace from the class name. It's the # same as Thor default except that the Generator at the end of the class # is removed. - # def self.namespace(name=nil) return super if name @namespace ||= super.sub(/_generator$/, '').sub(/:generators:/, ':') @@ -200,7 +194,6 @@ module Rails end # Make class option aware of Rails::Generators.options and Rails::Generators.aliases. - # def self.class_option(name, options={}) #:nodoc: options[:desc] = "Indicates when to generate #{name.to_s.humanize.downcase}" unless options.key?(:desc) options[:aliases] = default_aliases_for_option(name, options) @@ -208,14 +201,27 @@ module Rails super(name, options) end + # Returns the default source root for a given generator. This is used internally + # by rails to set its generators source root. If you want to customize your source + # root, you should use source_root. + def self.default_source_root + return unless base_name && generator_name + path = File.expand_path(File.join(base_name, generator_name, 'templates'), base_root) + path if File.exists?(path) + end + + # Returns the base root for a common set of generators. This is used to dynamically + # guess the default source root. + def self.base_root + File.dirname(__FILE__) + end + # Cache source root and add lib/generators/base/generator/templates to # source paths. - # def self.inherited(base) #:nodoc: super - # Cache source root, we need to do this, since __FILE__ is a relative value - # and can point to wrong directions when inside an specified directory. + # Invoke source_root so the default_source_root is set. base.source_root if base.name && base.name !~ /Base$/ diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index aa066fe3c4..667a123025 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -55,6 +55,7 @@ module Rails::Generators :desc => "Show this help message and quit" def initialize(*args) + raise Error, "Options should be given after the application name. For details run: rails --help" if args[0].blank? super if !options[:skip_activerecord] && !DATABASES.include?(options[:database]) raise Error, "Invalid value for --database option. Supported for preconfiguration are: #{DATABASES.join(", ")}." diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml index f600e054cf..4e6391e3d6 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml @@ -1,11 +1,11 @@ # PostgreSQL. Versions 7.4 and 8.x are supported. # -# Install the ruby-postgres driver: -# gem install ruby-postgres -# On Mac OS X: -# gem install ruby-postgres -- --include=/usr/local/pgsql +# Install the pg driver: +# gem install pg +# On Mac OS X with macports: +# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config # On Windows: -# gem install ruby-postgres +# gem install pg # Choose the win32 build. # Install PostgreSQL and put its /bin directory on your path. development: diff --git a/railties/lib/rails/generators/rails/app/templates/script/rails b/railties/lib/rails/generators/rails/app/templates/script/rails index b01d1ee183..11bc1edde9 100644 --- a/railties/lib/rails/generators/rails/app/templates/script/rails +++ b/railties/lib/rails/generators/rails/app/templates/script/rails @@ -1,8 +1,5 @@ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. -ENV_PATH = File.expand_path('../../config/environment', __FILE__) -BOOT_PATH = File.expand_path('../../config/boot', __FILE__) -APP_PATH = File.expand_path('../../config/application', __FILE__) - -require BOOT_PATH +APP_PATH = File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' diff --git a/railties/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt b/railties/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt index d8757460e4..d0575772bc 100644 --- a/railties/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt +++ b/railties/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt @@ -1,5 +1,3 @@ class <%= class_name %>Generator < Rails::Generators::NamedBase - def self.source_root - @source_root ||= File.expand_path('../templates', __FILE__) - end + source_root File.expand_path('../templates', __FILE__) end diff --git a/railties/lib/rails/generators/rails/mailer/USAGE b/railties/lib/rails/generators/rails/mailer/USAGE deleted file mode 100644 index a08d459739..0000000000 --- a/railties/lib/rails/generators/rails/mailer/USAGE +++ /dev/null @@ -1,15 +0,0 @@ -Description: - Stubs out a new mailer and its views. Pass the mailer name, either - CamelCased or under_scored, and an optional list of emails as arguments. - - This generates a mailer class in app/mailers and invokes your template - engine and test framework generators. - -Example: - `rails generate mailer Notifications signup forgot_password invoice` - - creates a Notifications mailer class, views, test, and fixtures: - Mailer: app/mailers/notifications.rb - Views: app/views/notifications/signup.erb [...] - Test: test/functional/notifications_test.rb - Fixtures: test/fixtures/notifications/signup [...] diff --git a/railties/lib/rails/generators/rails/mailer/mailer_generator.rb b/railties/lib/rails/generators/rails/mailer/mailer_generator.rb deleted file mode 100644 index 8993181d79..0000000000 --- a/railties/lib/rails/generators/rails/mailer/mailer_generator.rb +++ /dev/null @@ -1,14 +0,0 @@ -module Rails - module Generators - class MailerGenerator < NamedBase - argument :actions, :type => :array, :default => [], :banner => "method method" - check_class_collision - - def create_mailer_file - template "mailer.rb", File.join('app/mailers', class_path, "#{file_name}.rb") - end - - hook_for :template_engine, :test_framework - end - end -end diff --git a/railties/lib/rails/generators/rails/mailer/templates/mailer.rb b/railties/lib/rails/generators/rails/mailer/templates/mailer.rb deleted file mode 100644 index 7343eb28b3..0000000000 --- a/railties/lib/rails/generators/rails/mailer/templates/mailer.rb +++ /dev/null @@ -1,16 +0,0 @@ -class <%= class_name %> < ActionMailer::Base - default :from => "from@example.com" -<% for action in actions -%> - - # Subject can be set in your I18n file at config/locales/en.yml - # with the following lookup: - # - # en.actionmailer.<%= file_name %>.<%= action %>.subject - # - def <%= action %> - @greeting = "Hi" - - mail :to => "to@example.org" - end -<% end -%> -end |