aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails.rb23
-rw-r--r--railties/lib/rails/application.rb22
-rw-r--r--railties/lib/rails/application/railties.rb2
-rw-r--r--railties/lib/rails/commands.rb8
-rw-r--r--railties/lib/rails/commands/benchmarker.rb6
-rw-r--r--railties/lib/rails/commands/generate.rb4
-rw-r--r--railties/lib/rails/commands/plugin.rb4
-rw-r--r--railties/lib/rails/commands/profiler.rb6
-rw-r--r--railties/lib/rails/commands/runner.rb4
-rw-r--r--railties/lib/rails/commands/server.rb2
-rw-r--r--railties/lib/rails/engine.rb24
-rw-r--r--railties/lib/rails/engine/commands.rb38
-rw-r--r--railties/lib/rails/generators.rb5
-rw-r--r--railties/lib/rails/generators/actions.rb8
-rw-r--r--railties/lib/rails/generators/app_base.rb46
-rw-r--r--railties/lib/rails/generators/base.rb6
-rw-r--r--railties/lib/rails/generators/generated_attribute.rb2
-rw-r--r--railties/lib/rails/generators/named_base.rb4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Gemfile18
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb7
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml62
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml6
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml15
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml6
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt3
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/routes.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb2
-rw-r--r--railties/lib/rails/generators/rails/assets/USAGE2
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb16
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/Gemfile7
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/application.html.erb.tt14
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt7
-rw-r--r--railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb2
-rw-r--r--railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb2
-rw-r--r--railties/lib/rails/railtie.rb13
-rw-r--r--railties/lib/rails/railtie/configurable.rb2
-rw-r--r--railties/lib/rails/tasks/assets.rake22
38 files changed, 298 insertions, 128 deletions
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb
index cca0891835..df92934457 100644
--- a/railties/lib/rails.rb
+++ b/railties/lib/rails.rb
@@ -87,6 +87,29 @@ module Rails
RAILS_CACHE
end
+ # Returns all rails groups for loading based on:
+ #
+ # * The Rails environment;
+ # * The environment variable RAILS_GROUPS;
+ # * The optional hash given as argument with group dependencies;
+ #
+ # == Examples
+ #
+ # groups :assets => [:development, :test]
+ #
+ # # Returns
+ # # => [:default, :development, :assets] for Rails.env == "development"
+ # # => [:default, :production] for Rails.env == "production"
+ #
+ def groups(hash={})
+ env = Rails.env
+ groups = [:default, env]
+ groups.concat ENV["RAILS_GROUPS"].to_s.split(",")
+ groups.concat hash.map { |k,v| k if v.map(&:to_s).include?(env) }
+ groups.compact!
+ groups
+ end
+
def version
VERSION::STRING
end
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 953233d774..fe29668c72 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -78,10 +78,6 @@ module Rails
require environment if environment
end
- def eager_load! #:nodoc:
- railties.all(&:eager_load!)
- super
- end
def reload_routes!
routes_reloader.reload!
@@ -100,22 +96,12 @@ module Rails
def load_tasks(app=self)
initialize_tasks
- railties.all { |r| r.load_tasks(app) }
- super
- self
- end
-
- def load_generators(app=self)
- initialize_generators
- railties.all { |r| r.load_generators(app) }
- Rails::Generators.configure!(app.config.generators)
super
self
end
def load_console(app=self)
initialize_console
- railties.all { |r| r.load_console(app) }
super
self
end
@@ -138,6 +124,10 @@ module Rails
@config ||= Application::Configuration.new(find_root_with_flag("config.ru", Dir.pwd))
end
+ def to_app
+ self
+ end
+
protected
alias :build_middleware_stack :app
@@ -195,10 +185,6 @@ module Rails
end
end
- def initialize_generators
- require "rails/generators"
- end
-
def initialize_console
require "pp"
require "rails/console/app"
diff --git a/railties/lib/rails/application/railties.rb b/railties/lib/rails/application/railties.rb
index 4fc5e92837..8f3a3e8bbb 100644
--- a/railties/lib/rails/application/railties.rb
+++ b/railties/lib/rails/application/railties.rb
@@ -4,7 +4,7 @@ module Rails
class Application < Engine
class Railties < Rails::Engine::Railties
def all(&block)
- @all ||= railties + engines + super
+ @all ||= railties + engines + plugins
@all.each(&block) if block
@all
end
diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb
index 39627a3094..5e55aeada9 100644
--- a/railties/lib/rails/commands.rb
+++ b/railties/lib/rails/commands.rb
@@ -23,11 +23,7 @@ when 'generate', 'destroy', 'plugin'
require APP_PATH
Rails.application.require_environment!
- if defined?(ENGINE_PATH) && engine = Rails::Engine.find(ENGINE_PATH)
- Rails.application.load_generators(engine)
- else
- Rails.application.load_generators
- end
+ Rails.application.load_generators
require "rails/commands/#{command}"
end
@@ -95,7 +91,7 @@ In addition to those, there are:
benchmarker See how fast a piece of code runs
profiler Get profile information from a piece of code
plugin Install a plugin
- runner Run a piece of code in the application environment
+ runner Run a piece of code in the application environment (short-cut alias: "r")
All commands can be run with -h for more information.
EOT
diff --git a/railties/lib/rails/commands/benchmarker.rb b/railties/lib/rails/commands/benchmarker.rb
index b06c915ac3..6c52d0f70f 100644
--- a/railties/lib/rails/commands/benchmarker.rb
+++ b/railties/lib/rails/commands/benchmarker.rb
@@ -9,7 +9,7 @@ ARGV.pop
def options
options = {}
defaults = ActiveSupport::Testing::Performance::DEFAULTS
-
+
OptionParser.new do |opt|
opt.banner = "Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS]"
opt.on('-r', '--runs N', Numeric, 'Number of runs.', "Default: #{defaults[:runs]}") { |r| options[:runs] = r }
@@ -17,13 +17,13 @@ def options
opt.on('-m', '--metrics a,b,c', Array, 'Metrics to use.', "Default: #{defaults[:metrics].join(",")}") { |m| options[:metrics] = m.map(&:to_sym) }
opt.parse!(ARGV)
end
-
+
options
end
class BenchmarkerTest < ActionDispatch::PerformanceTest
self.profile_options = options
-
+
ARGV.each do |expression|
eval <<-RUBY
def test_#{expression.parameterize('_')}
diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb
index b6f9a003d1..1fb2d98834 100644
--- a/railties/lib/rails/commands/generate.rb
+++ b/railties/lib/rails/commands/generate.rb
@@ -7,4 +7,6 @@ if ARGV.first.in?([nil, "-h", "--help"])
end
name = ARGV.shift
-Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => Rails.root
+
+root = defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
+Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => root
diff --git a/railties/lib/rails/commands/plugin.rb b/railties/lib/rails/commands/plugin.rb
index 048af7cbef..4df849447d 100644
--- a/railties/lib/rails/commands/plugin.rb
+++ b/railties/lib/rails/commands/plugin.rb
@@ -313,11 +313,11 @@ module Commands
o.separator ""
o.separator "EXAMPLES"
o.separator " Install a plugin from a subversion URL:"
- o.separator " #{@script_name} plugin install http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder\n"
+ o.separator " #{@script_name} plugin install http://example.com/my_svn_plugin\n"
o.separator " Install a plugin from a git URL:"
o.separator " #{@script_name} plugin install git://github.com/SomeGuy/my_awesome_plugin.git\n"
o.separator " Install a plugin and add a svn:externals entry to vendor/plugins"
- o.separator " #{@script_name} plugin install -x continuous_builder\n"
+ o.separator " #{@script_name} plugin install -x my_svn_plugin\n"
end
end
diff --git a/railties/lib/rails/commands/profiler.rb b/railties/lib/rails/commands/profiler.rb
index 94cf32d32d..ea6347c918 100644
--- a/railties/lib/rails/commands/profiler.rb
+++ b/railties/lib/rails/commands/profiler.rb
@@ -6,7 +6,7 @@ require 'active_support/testing/performance'
def options
options = {}
defaults = ActiveSupport::Testing::Performance::DEFAULTS
-
+
OptionParser.new do |opt|
opt.banner = "Usage: rails benchmarker 'Ruby.code' 'Ruby.more_code' ... [OPTS]"
opt.on('-r', '--runs N', Numeric, 'Number of runs.', "Default: #{defaults[:runs]}") { |r| options[:runs] = r }
@@ -15,13 +15,13 @@ def options
opt.on('-f', '--formats x,y,z', Array, 'Formats to output to.', "Default: #{defaults[:formats].join(",")}") { |m| options[:formats] = m.map(&:to_sym) }
opt.parse!(ARGV)
end
-
+
options
end
class ProfilerTest < ActionDispatch::PerformanceTest
self.profile_options = options
-
+
ARGV.each do |expression|
eval <<-RUBY
def test_#{expression.parameterize('_')}
diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb
index f8b00e7249..e8cc5d9e3b 100644
--- a/railties/lib/rails/commands/runner.rb
+++ b/railties/lib/rails/commands/runner.rb
@@ -4,6 +4,10 @@ require 'rbconfig'
options = { :environment => (ENV['RAILS_ENV'] || "development").dup }
code_or_file = nil
+if ARGV.first.nil?
+ ARGV.push "-h"
+end
+
ARGV.clone.options do |opts|
script_name = File.basename($0)
opts.banner = "Usage: runner [options] ('Some.ruby(code)' or a filename)"
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index 91c87514cf..23392276d5 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -43,7 +43,7 @@ module Rails
end
def app
- @app ||= super.instance
+ @app ||= super.respond_to?(:to_app) ? super.to_app : super
end
def opt_parser
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 383be1802f..52c89274e7 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -330,6 +330,14 @@ module Rails
autoload :Configuration, "rails/engine/configuration"
autoload :Railties, "rails/engine/railties"
+ def load_generators(app=self)
+ initialize_generators
+ railties.all { |r| r.load_generators(app) }
+ Rails::Generators.configure!(app.config.generators)
+ super
+ self
+ end
+
class << self
attr_accessor :called_from, :isolated
alias :isolated? :isolated
@@ -387,12 +395,20 @@ module Rails
delegate :middleware, :root, :paths, :to => :config
delegate :engine_name, :isolated?, :to => "self.class"
- def load_tasks(*)
+ def load_tasks(app=self)
+ railties.all { |r| r.load_tasks(app) }
super
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
end
-
+
+ def load_console(app=self)
+ railties.all { |r| r.load_console(app) }
+ super
+ end
+
def eager_load!
+ railties.all(&:eager_load!)
+
config.eager_load_paths.each do |load_path|
matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
@@ -567,6 +583,10 @@ module Rails
protected
+ def initialize_generators
+ require "rails/generators"
+ end
+
def routes?
defined?(@routes)
end
diff --git a/railties/lib/rails/engine/commands.rb b/railties/lib/rails/engine/commands.rb
new file mode 100644
index 0000000000..3b0920e213
--- /dev/null
+++ b/railties/lib/rails/engine/commands.rb
@@ -0,0 +1,38 @@
+require 'active_support/core_ext/object/inclusion'
+
+ARGV << '--help' if ARGV.empty?
+
+aliases = {
+ "g" => "generate"
+}
+
+command = ARGV.shift
+command = aliases[command] || command
+
+require ENGINE_PATH
+engine = ::Rails::Engine.find(ENGINE_ROOT)
+
+case command
+when 'generate', 'destroy'
+ require 'rails/generators'
+ Rails::Generators.namespace = engine.railtie_namespace
+ engine.load_generators
+ require "rails/commands/#{command}"
+
+when '--version', '-v'
+ ARGV.unshift '--version'
+ require 'rails/commands/application'
+
+else
+ puts "Error: Command not recognized" unless command.in?(['-h', '--help'])
+ puts <<-EOT
+Usage: rails COMMAND [ARGS]
+
+The common rails commands available for engines are:
+ generate Generate new code (short-cut alias: "g")
+ destroy Undo code generated with "generate"
+
+All commands can be run with -h for more information.
+ EOT
+ exit(1)
+end
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 09e505a75b..ea9f023511 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -20,6 +20,8 @@ module Rails
autoload :ResourceHelpers, 'rails/generators/resource_helpers'
autoload :TestCase, 'rails/generators/test_case'
+ mattr_accessor :namespace
+
DEFAULT_ALIASES = {
:rails => {
:actions => '-a',
@@ -297,9 +299,6 @@ module Rails
return
rescue LoadError => e
raise unless e.message =~ /#{Regexp.escape(path)}$/
- rescue NameError => e
- raise unless e.message =~ /Rails::Generator([\s(::)]|$)/
- warn "[WARNING] Could not load generator #{path.inspect} because it's a Rails 2.x generator, which is not supported anymore. Error: #{e.message}.\n#{e.backtrace.join("\n")}"
rescue Exception => e
warn "[WARNING] Could not load generator #{path.inspect}. Error: #{e.message}.\n#{e.backtrace.join("\n")}"
end
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index d31a3262e3..433a56dc57 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -114,11 +114,11 @@ module Rails
# git :add => "this.file that.rb"
# git :add => "onefile.rb", :rm => "badfile.cxx"
#
- def git(command={})
- if command.is_a?(Symbol)
- run "git #{command}"
+ def git(commands={})
+ if commands.is_a?(Symbol)
+ run "git #{commands}"
else
- command.each do |command, options|
+ commands.each do |command, options|
run "git #{command} #{options}"
end
end
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index 7972c72c1e..378eceb4c3 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -10,7 +10,7 @@ module Rails
module Generators
class AppBase < Base
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
- JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql )
+ JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc )
DATABASES.concat(JDBC_DATABASES)
attr_accessor :rails_template
@@ -64,8 +64,8 @@ module Rails
def initialize(*args)
@original_wd = Dir.pwd
-
super
+ convert_database_option_for_jruby
end
protected
@@ -157,14 +157,26 @@ module Rails
when "postgresql" then "pg"
when "frontbase" then "ruby-frontbase"
when "mysql" then "mysql2"
- when "jdbcmysql" then "activerecord-jdbcmysql-adapter"
- when "jdbcsqlite3" then "activerecord-jdbcsqlite3-adapter"
- when "jdbcpostgresql" then "activerecord-jdbcpostgresql-adapter"
+ when "jdbcmysql" then "activerecord-jdbcmysql-adapter"
+ when "jdbcsqlite3" then "activerecord-jdbcsqlite3-adapter"
+ when "jdbcpostgresql" then "activerecord-jdbcpostgresql-adapter"
+ when "jdbc" then "activerecord-jdbc-adapter"
else options[:database]
end
end
- def gem_for_ruby_debugger
+ def convert_database_option_for_jruby
+ if defined?(JRUBY_VERSION)
+ case options[:database]
+ when "oracle" then options[:database].replace "jdbc"
+ when "postgresql" then options[:database].replace "jdbcpostgresql"
+ when "mysql" then options[:database].replace "jdbcmysql"
+ when "sqlite3" then options[:database].replace "jdbcsqlite3"
+ end
+ end
+ end
+
+ def ruby_debugger_gemfile_entry
if RUBY_VERSION < "1.9"
"gem 'ruby-debug'"
else
@@ -172,7 +184,7 @@ module Rails
end
end
- def gem_for_turn
+ def turn_gemfile_entry
unless RUBY_VERSION < "1.9.2" || options[:skip_test_unit]
<<-GEMFILE.strip_heredoc
group :test do
@@ -183,18 +195,24 @@ module Rails
end
end
- def gem_for_javascript
+ def javascript_gemfile_entry
"gem '#{options[:javascript]}-rails'" unless options[:skip_javascript]
end
def bundle_command(command)
- require 'bundler'
- require 'bundler/cli'
-
say_status :run, "bundle #{command}"
- Bundler::CLI.new.send(command)
- rescue
- say_status :failure, "bundler raised an exception, are you offline?", :red
+
+ # We are going to shell out rather than invoking Bundler::CLI.new(command)
+ # because `rails new` loads the Thor gem and on the other hand bundler uses
+ # its own vendored Thor, which could be a different version. Running both
+ # things in the same process is a recipe for a night with paracetamol.
+ #
+ # We use backticks and #print here instead of vanilla #system because it
+ # is easier to silence stdout in the existing test suite this way. The
+ # end-user gets the bundler commands called anyway, so no big deal.
+ #
+ # Thanks to James Tucker for the Gem tricks involved in this call.
+ print `"#{Gem.ruby}" -rubygems "#{Gem.bin_path('bundler', 'bundle')}" #{command}`
end
def run_bundle
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb
index 1f6a7a2f59..b9dc31457a 100644
--- a/railties/lib/rails/generators/base.rb
+++ b/railties/lib/rails/generators/base.rb
@@ -259,9 +259,9 @@ module Rails
extra << false unless Object.method(:const_defined?).arity == 1
# Extract the last Module in the nesting
- last = nesting.inject(Object) do |last, nest|
- break unless last.const_defined?(nest, *extra)
- last.const_get(nest)
+ last = nesting.inject(Object) do |last_module, nest|
+ break unless last_module.const_defined?(nest, *extra)
+ last_module.const_get(nest)
end
if last && last.const_defined?(last_name.camelize, *extra)
diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb
index 9450894b05..f9f89c9f1d 100644
--- a/railties/lib/rails/generators/generated_attribute.rb
+++ b/railties/lib/rails/generators/generated_attribute.rb
@@ -7,7 +7,7 @@ module Rails
attr_accessor :name, :type
def initialize(name, type)
- raise Thor::Error, "Missing type for attribute '#{name}'.\nExample: '#{name}:string' where string is the type." if type.blank?
+ type = :string if type.blank?
@name, @type = name, type.to_sym
end
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb
index 7e7f8d2d08..c6c0392f43 100644
--- a/railties/lib/rails/generators/named_base.rb
+++ b/railties/lib/rails/generators/named_base.rb
@@ -63,9 +63,7 @@ module Rails
end
def namespace
- @namespace ||= if defined?(Rails) && Rails.application
- Rails.application.class.parents.detect { |n| n.respond_to?(:_railtie) }
- end
+ Rails::Generators.namespace
end
def namespaced?
diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile
index ebe38bf8e6..cd674ddbdd 100644
--- a/railties/lib/rails/generators/rails/app/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/app/templates/Gemfile
@@ -5,13 +5,17 @@ source 'http://rubygems.org'
<%= database_gemfile_entry -%>
<%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) -%>
-# Asset template engines
<%= "gem 'json'\n" if RUBY_VERSION < "1.9.2" -%>
-gem 'sass-rails'
-gem 'coffee-script'
-gem 'uglifier'
-<%= gem_for_javascript %>
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails'
+ gem 'coffee-script'
+ gem 'uglifier'
+end
+
+<%= javascript_gemfile_entry %>
# Use unicorn as the web server
# gem 'unicorn'
@@ -20,6 +24,6 @@ gem 'uglifier'
# gem 'capistrano'
# To use debugger
-# <%= gem_for_ruby_debugger %>
+# <%= ruby_debugger_gemfile_entry %>
-<%= gem_for_turn -%>
+<%= turn_gemfile_entry -%>
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
index 37c2fb1263..7f623a7af9 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -11,9 +11,10 @@ require "active_resource/railtie"
<%= comment_if :skip_test_unit %> require "rails/test_unit/railtie"
<% end -%>
-# If you have a Gemfile, require the gems listed there, including any gems
-# you've limited to :test, :development, or :production.
-Bundler.require(:default, Rails.env) if defined?(Bundler)
+# If you have a Gemfile, require the default gems, the ones in the
+# current environment and also include :assets gems if in development
+# or test environments.
+Bundler.require *Rails.groups(:assets => %w(development test)) if defined?(Bundler)
module <%= app_const_base %>
class Application < Rails::Application
diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml
new file mode 100644
index 0000000000..1d2bf08b91
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml
@@ -0,0 +1,62 @@
+# If you are using mssql, derby, hsqldb, or h2 with one of the
+# ActiveRecord JDBC adapters, install the appropriate driver, e.g.,:
+# gem install activerecord-jdbcmssql-adapter
+#
+# Configure using Gemfile:
+# gem 'activerecord-jdbcmssql-adapter'
+#
+#development:
+# adapter: mssql
+# username: <%= app_name %>
+# password:
+# host: localhost
+# database: <%= app_name %>_development
+#
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+#
+#test:
+# adapter: mssql
+# username: <%= app_name %>
+# password:
+# host: localhost
+# database: <%= app_name %>_test
+#
+#production:
+# adapter: mssql
+# username: <%= app_name %>
+# password:
+# host: localhost
+# database: <%= app_name %>_production
+
+# If you are using oracle, db2, sybase, informix or prefer to use the plain
+# JDBC adapter, configure your database setting as the example below (requires
+# you to download and manually install the database vendor's JDBC driver .jar
+# file). See your driver documentation for the apropriate driver class and
+# connection string:
+
+development:
+ adapter: jdbc
+ username: <%= app_name %>
+ password:
+ driver:
+ url: jdbc:db://localhost/<%= app_name %>_development
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+
+test:
+ adapter: jdbc
+ username: <%= app_name %>
+ password:
+ driver:
+ url: jdbc:db://localhost/<%= app_name %>_test
+
+production:
+ adapter: jdbc
+ username: <%= app_name %>
+ password:
+ driver:
+ url: jdbc:db://localhost/<%= app_name %>_production
diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml
index 6bf83e86a5..5a594ac1f3 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml
+++ b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml
@@ -9,7 +9,7 @@
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
- adapter: jdbcmysql
+ adapter: mysql
database: <%= app_name %>_development
username: root
password:
@@ -19,14 +19,14 @@ development:
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
- adapter: jdbcmysql
+ adapter: mysql
database: <%= app_name %>_test
username: root
password:
host: localhost
production:
- adapter: jdbcmysql
+ adapter: mysql
database: <%= app_name %>_production
username: root
password:
diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml
index 0c7f45322b..996ff4baa3 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml
+++ b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml
@@ -1,19 +1,10 @@
# PostgreSQL. Versions 7.4 and 8.x are supported.
#
-# 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 pg
-# Choose the win32 build.
-# Install PostgreSQL and put its /bin directory on your path.
-#
# Configure Using Gemfile
# gem 'activerecord-jdbcpostgresql-adapter'
development:
- adapter: jdbcpostgresql
+ adapter: postgresql
encoding: unicode
database: <%= app_name %>_development
username: <%= app_name %>
@@ -38,14 +29,14 @@ development:
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
- adapter: jdbcpostgresql
+ adapter: postgresql
encoding: unicode
database: <%= app_name %>_test
username: <%= app_name %>
password:
production:
- adapter: jdbcpostgresql
+ adapter: postgresql
encoding: unicode
database: <%= app_name %>_production
username: <%= app_name %>
diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml
index 6d241d57ae..175f3eb3db 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml
+++ b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml
@@ -5,16 +5,16 @@
# gem 'activerecord-jdbcsqlite3-adapter'
#
development:
- adapter: jdbcsqlite3
+ adapter: sqlite3
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
- adapter: jdbcsqlite3
+ adapter: sqlite3
database: db/test.sqlite3
production:
- adapter: jdbcsqlite3
+ adapter: sqlite3
database: db/production.sqlite3
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
index 60e26755fe..06ed890e05 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -14,9 +14,6 @@
# Compress JavaScripts and CSS
config.assets.compress = true
- # Specify the default JavaScript compressor
- config.assets.js_compressor = :uglifier
-
# Specifies the header that your server uses for sending files
# (comment out if your front-end server doesn't support this)
config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx
diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt
index e56195da80..fa1548db8b 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt
@@ -1,7 +1,7 @@
# Be sure to restart your server when you modify this file.
#
-# This file contains the settings for ActionController::ParametersWrapper
-# which will be enabled by default in the upcoming version of Ruby on Rails.
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActionController::Base.wrap_parameters <%= key_value :format, "[:json]" %>
diff --git a/railties/lib/rails/generators/rails/app/templates/config/routes.rb b/railties/lib/rails/generators/rails/app/templates/config/routes.rb
index d50f536164..ea81748464 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/routes.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/routes.rb
@@ -54,5 +54,5 @@
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id(.:format)))'
+ # match ':controller(/:action(/:id))(.:format)'
end
diff --git a/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb b/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
index 5d1be041a5..3fea27b916 100644
--- a/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
+++ b/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb
@@ -5,7 +5,7 @@ class BrowsingTest < ActionDispatch::PerformanceTest
# Refer to the documentation for all available options
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
# :output => 'tmp/performance', :formats => [:flat] }
-
+
def test_homepage
get '/'
end
diff --git a/railties/lib/rails/generators/rails/assets/USAGE b/railties/lib/rails/generators/rails/assets/USAGE
index c5375cdc06..d2e5ed4482 100644
--- a/railties/lib/rails/generators/rails/assets/USAGE
+++ b/railties/lib/rails/generators/rails/assets/USAGE
@@ -7,7 +7,7 @@ Description:
This generates a JavaScript stub in app/assets/javascripts and a stylesheet
stub in app/assets/stylesheets.
-
+
If CoffeeScript is available, JavaScripts will be generated with the .coffee extension.
If Sass 3 is available, stylesheets will be generated with the .scss extension.
diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
index 11867a4cd7..7c0a2b9cf4 100644
--- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
+++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -11,15 +11,15 @@ module Rails
def app
if mountable?
directory "app"
- template "#{app_templates_dir}/app/views/layouts/application.html.erb.tt",
+ template "app/views/layouts/application.html.erb.tt",
"app/views/layouts/#{name}/application.html.erb"
- empty_directory_with_gitkeep "app/assets/images"
+ empty_directory_with_gitkeep "app/assets/images/#{name}"
elsif full?
empty_directory_with_gitkeep "app/models"
empty_directory_with_gitkeep "app/controllers"
empty_directory_with_gitkeep "app/views"
empty_directory_with_gitkeep "app/helpers"
- empty_directory_with_gitkeep "app/assets/images"
+ empty_directory_with_gitkeep "app/assets/images/#{name}"
end
end
@@ -108,9 +108,9 @@ task :default => :test
def stylesheets
if mountable?
copy_file "#{app_templates_dir}/app/assets/stylesheets/application.css",
- "app/assets/stylesheets/application.css"
+ "app/assets/stylesheets/#{name}/application.css"
elsif full?
- empty_directory_with_gitkeep "app/assets/stylesheets"
+ empty_directory_with_gitkeep "app/assets/stylesheets/#{name}"
end
end
@@ -119,13 +119,15 @@ task :default => :test
if mountable?
template "#{app_templates_dir}/app/assets/javascripts/application.js.tt",
- "app/assets/javascripts/application.js"
+ "app/assets/javascripts/#{name}/application.js"
elsif full?
- empty_directory_with_gitkeep "app/assets/javascripts"
+ empty_directory_with_gitkeep "app/assets/javascripts/#{name}"
end
end
def script(force = false)
+ return unless full?
+
directory "script", :force => force do |content|
"#{shebang}\n" + content
end
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
index c28e568711..7e6eb18341 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
@@ -7,9 +7,8 @@ source "http://rubygems.org"
<% end -%>
<% if mountable? -%>
-<%= gem_for_javascript -%>
+<%= javascript_gemfile_entry -%>
<% end -%>
-if RUBY_VERSION < '1.9'
- gem "ruby-debug", ">= 0.10.3"
-end
+# To use debugger
+# <%= ruby_debugger_gemfile_entry %> \ No newline at end of file
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/application.html.erb.tt b/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/application.html.erb.tt
new file mode 100644
index 0000000000..01550dec2f
--- /dev/null
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/app/views/layouts/application.html.erb.tt
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title><%= camelized %></title>
+ <%%= stylesheet_link_tag "<%= name %>/application" %>
+ <%%= javascript_include_tag "<%= name %>/application" %>
+ <%%= csrf_meta_tags %>
+</head>
+<body>
+
+<%%= yield %>
+
+</body>
+</html>
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt b/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt
index 65d82abf6d..aa87d1b50c 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt
@@ -1,4 +1,7 @@
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
-ENGINE_PATH = File.expand_path('../..', __FILE__)
-load File.expand_path('../../<%= dummy_path %>/script/rails', __FILE__)
+ENGINE_ROOT = File.expand_path('../..', __FILE__)
+ENGINE_PATH = File.expand_path('../../lib/<%= name -%>/engine', __FILE__)
+
+require 'rails/all'
+require 'rails/engine/commands'
diff --git a/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb b/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb
index e7a06e4a73..dea7e22196 100644
--- a/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb
+++ b/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb
@@ -1,8 +1,6 @@
require 'test_helper'
class <%= class_name %>Test < ActionDispatch::IntegrationTest
- fixtures :all
-
# test "the truth" do
# assert true
# end
diff --git a/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
index 14a878328b..d296b26b16 100644
--- a/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
+++ b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb
@@ -5,7 +5,7 @@ class <%= class_name %>Test < ActionDispatch::PerformanceTest
# Refer to the documentation for all available options
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
# :output => 'tmp/performance', :formats => [:flat] }
-
+
def test_homepage
get '/'
end
diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb
index 65c567d72f..8c88b25617 100644
--- a/railties/lib/rails/railtie.rb
+++ b/railties/lib/rails/railtie.rb
@@ -1,6 +1,7 @@
require 'rails/initializable'
require 'rails/configuration'
require 'active_support/inflector'
+require 'active_support/core_ext/module/introspection'
module Rails
# Railtie is the core of the Rails framework and provides several hooks to extend
@@ -83,7 +84,7 @@ module Rails
# == Loading rake tasks and generators
#
# If your railtie has rake tasks, you can tell Rails to load them through the method
- # rake tasks:
+ # rake_tasks:
#
# class MyRailtie < Rails::Railtie
# rake_tasks do
@@ -173,11 +174,11 @@ module Rails
def eager_load!
end
- def load_console(app)
+ def load_console(app=self)
self.class.console.each { |block| block.call(app) }
end
- def load_tasks(app)
+ def load_tasks(app=self)
extend Rake::DSL if defined? Rake::DSL
self.class.rake_tasks.each { |block| block.call(app) }
@@ -189,8 +190,12 @@ module Rails
end
end
- def load_generators(app)
+ def load_generators(app=self)
self.class.generators.each { |block| block.call(app) }
end
+
+ def railtie_namespace
+ @railtie_namespace ||= self.class.parents.detect { |n| n.respond_to?(:_railtie) }
+ end
end
end
diff --git a/railties/lib/rails/railtie/configurable.rb b/railties/lib/rails/railtie/configurable.rb
index 920ab67ff1..53796c74cf 100644
--- a/railties/lib/rails/railtie/configurable.rb
+++ b/railties/lib/rails/railtie/configurable.rb
@@ -1,3 +1,5 @@
+require 'active_support/concern'
+
module Rails
class Railtie
module Configurable
diff --git a/railties/lib/rails/tasks/assets.rake b/railties/lib/rails/tasks/assets.rake
index 5f87edc9e2..0236350576 100644
--- a/railties/lib/rails/tasks/assets.rake
+++ b/railties/lib/rails/tasks/assets.rake
@@ -1,18 +1,26 @@
namespace :assets do
desc "Compile all the assets named in config.assets.precompile"
- task :precompile => :environment do
- # Give assets access to asset_path
- Sprockets::Helpers::RailsHelper
+ task :precompile do
+ if ENV["RAILS_GROUPS"].to_s.empty?
+ ENV["RAILS_GROUPS"] = "assets"
+ Kernel.exec $0, *ARGV
+ else
+ Rake::Task["environment"].invoke
+ Sprockets::Helpers::RailsHelper
- assets = Rails.application.config.assets.precompile
- Rails.application.assets.precompile(*assets)
+ assets = Rails.application.config.assets.precompile
+ Rails.application.assets.precompile(*assets)
+ end
end
desc "Remove compiled assets"
task :clean => :environment do
assets = Rails.application.config.assets
public_asset_path = Rails.public_path + assets.prefix
- file_list = FileList.new("#{public_asset_path}/*.js", "#{public_asset_path}/*.css")
- file_list.each{ |file| rm file }
+ file_list = FileList.new("#{public_asset_path}/**/*")
+ file_list.each do |file|
+ rm_rf file
+ rm_rf "#{file}.gz"
+ end
end
end