aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-08-31 22:11:50 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-08-31 22:11:50 +0100
commitbae00bb1cc392e1cf408369809b9cf85468bef42 (patch)
tree17103af6eeb5de96c72beda1debce28950cc7fea /railties
parent93c76b2fb08668bc4b8364cc8051476e6d1d15ba (diff)
parentffd2cf167040b60c26d97c01598560c87bd4b2d3 (diff)
downloadrails-bae00bb1cc392e1cf408369809b9cf85468bef42.tar.gz
rails-bae00bb1cc392e1cf408369809b9cf85468bef42.tar.bz2
rails-bae00bb1cc392e1cf408369809b9cf85468bef42.zip
Merge commit 'mainstream/master'
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/commands/dbconsole.rb12
-rw-r--r--railties/lib/generators.rb93
-rw-r--r--railties/lib/generators/actions.rb12
-rw-r--r--railties/lib/generators/active_record.rb1
-rw-r--r--railties/lib/generators/base.rb52
-rw-r--r--railties/lib/generators/erb/scaffold/scaffold_generator.rb5
-rw-r--r--railties/lib/generators/erb/scaffold/templates/_form.html.erb17
-rw-r--r--railties/lib/generators/erb/scaffold/templates/edit.html.erb16
-rw-r--r--railties/lib/generators/erb/scaffold/templates/layout.html.erb2
-rw-r--r--railties/lib/generators/erb/scaffold/templates/new.html.erb16
-rw-r--r--railties/lib/generators/named_base.rb62
-rw-r--r--railties/lib/generators/rails/app/app_generator.rb2
-rw-r--r--railties/lib/generators/rails/app/templates/config/databases/sqlite2.yml19
-rw-r--r--railties/lib/generators/rails/generator/generator_generator.rb2
-rw-r--r--railties/lib/generators/rails/resource/resource_generator.rb16
-rw-r--r--railties/lib/generators/rails/scaffold/scaffold_generator.rb3
-rw-r--r--railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb5
-rw-r--r--railties/lib/generators/rails/stylesheets/templates/scaffold.css8
-rw-r--r--railties/lib/generators/resource_helpers.rb74
-rw-r--r--railties/lib/generators/test_unit/scaffold/scaffold_generator.rb3
-rw-r--r--railties/lib/rails/plugin.rb12
-rw-r--r--railties/lib/rails/plugin/loader.rb9
-rw-r--r--railties/lib/tasks/databases.rake8
-rw-r--r--railties/lib/vendor/thor-0.11.6/CHANGELOG.rdoc (renamed from railties/lib/vendor/thor-0.11.5/CHANGELOG.rdoc)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/LICENSE (renamed from railties/lib/vendor/thor-0.11.5/LICENSE)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/README.rdoc (renamed from railties/lib/vendor/thor-0.11.5/README.rdoc)0
-rwxr-xr-xrailties/lib/vendor/thor-0.11.6/bin/rake2thor (renamed from railties/lib/vendor/thor-0.11.5/bin/rake2thor)0
-rwxr-xr-xrailties/lib/vendor/thor-0.11.6/bin/thor (renamed from railties/lib/vendor/thor-0.11.5/bin/thor)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor.rb)2
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/actions.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/actions.rb)31
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/actions/create_file.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/actions/create_file.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/actions/directory.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/actions/directory.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/actions/empty_directory.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/actions/empty_directory.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/actions/file_manipulation.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/actions/file_manipulation.rb)58
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/actions/inject_into_file.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/actions/inject_into_file.rb)63
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/base.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/base.rb)7
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/core_ext/hash_with_indifferent_access.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/hash_with_indifferent_access.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/core_ext/ordered_hash.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/ordered_hash.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/error.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/error.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/group.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/group.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/invocation.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/invocation.rb)2
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/parser.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/parser.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/parser/argument.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/parser/argument.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/parser/arguments.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/parser/arguments.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/parser/option.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/parser/option.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/parser/options.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/parser/options.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/rake_compat.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/rake_compat.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/runner.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/runner.rb)4
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/shell.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/shell.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/shell/basic.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/shell/basic.rb)5
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/shell/color.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/shell/color.rb)0
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/task.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/task.rb)20
-rw-r--r--railties/lib/vendor/thor-0.11.6/lib/thor/util.rb (renamed from railties/lib/vendor/thor-0.11.5/lib/thor/util.rb)17
-rw-r--r--railties/test/fixtures/plugins/engines/engine/config/locales/en.yml2
-rw-r--r--railties/test/fixtures/vendor/another_gem_path/xspec/lib/generators/xspec_generator.rb2
-rw-r--r--railties/test/fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb (renamed from railties/test/fixtures/vendor/gems/gems/mspec/lib/generators/mspec_generator.rb)0
-rw-r--r--railties/test/generators/generators_test_helper.rb7
-rw-r--r--railties/test/generators/scaffold_generator_test.rb1
-rw-r--r--railties/test/generators/session_migration_generator_test.rb13
-rw-r--r--railties/test/generators_test.rb19
-rw-r--r--railties/test/initializer_test.rb1
-rw-r--r--railties/test/plugin_loader_test.rb8
63 files changed, 425 insertions, 288 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 782afd5aa4..d6311f77a0 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*Edge*
+* I18n support for plugins. #2325 [Antonio Tapiador, Sven Fuchs]
+
* Ruby 1.9: use UTF-8 for default internal and external encodings. [Jeremy Kemper]
* Added db/seeds.rb as a default file for storing seed data for the database. Can be loaded with rake db:seed (or created alongside the db with db:setup). (This is also known as the "Stop Putting Gawd Damn Seed Data In Your Migrations" feature) [DHH]
diff --git a/railties/lib/commands/dbconsole.rb b/railties/lib/commands/dbconsole.rb
index 8002264f7e..e6f11a45db 100644
--- a/railties/lib/commands/dbconsole.rb
+++ b/railties/lib/commands/dbconsole.rb
@@ -33,11 +33,15 @@ end
def find_cmd(*commands)
dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR)
commands += commands.map{|cmd| "#{cmd}.exe"} if RUBY_PLATFORM =~ /win32/
- commands.detect do |cmd|
- dirs_on_path.detect do |path|
- File.executable? File.join(path, cmd)
+
+ full_path_command = nil
+ found = commands.detect do |cmd|
+ dir = dirs_on_path.detect do |path|
+ full_path_command = File.join(path, cmd)
+ File.executable? full_path_command
end
- end || abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
+ end
+ found ? full_path_command : abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
end
case config["adapter"]
diff --git a/railties/lib/generators.rb b/railties/lib/generators.rb
index c97c61507a..879abb1c41 100644
--- a/railties/lib/generators.rb
+++ b/railties/lib/generators.rb
@@ -11,7 +11,7 @@ end
$:.unshift(File.dirname(__FILE__))
-require 'vendor/thor-0.11.5/lib/thor'
+require 'vendor/thor-0.11.6/lib/thor'
require 'generators/base'
require 'generators/named_base'
@@ -45,7 +45,6 @@ module Rails
},
:erb => {
- :form => false,
:layout => true
},
@@ -76,39 +75,37 @@ module Rails
}
def self.aliases #:nodoc:
- @@aliases ||= DEFAULT_ALIASES.dup
+ @aliases ||= DEFAULT_ALIASES.dup
end
def self.options #:nodoc:
- @@options ||= DEFAULT_OPTIONS.dup
+ @options ||= DEFAULT_OPTIONS.dup
end
- # Get paths only from loaded rubygems. In other words, to use rspec
- # generators, you first have to ensure that rspec gem was already loaded.
+ # We have two scenarios here: when rubygems is loaded and when bundler is
+ # being used. If rubygems is loaded, we get all generators paths from loaded
+ # specs. Otherwise we just have to look into vendor/gems/gems.
#
- def self.rubygems_generators_paths
+ def self.gems_generators_paths
paths = []
- return paths unless defined?(Gem)
- Gem.loaded_specs.each do |name, spec|
- generator_path = File.join(spec.full_gem_path, "lib/generators")
- paths << generator_path if File.exist?(generator_path)
+ if defined?(Gem) && Gem.respond_to?(:loaded_specs)
+ Gem.loaded_specs.each do |name, spec|
+ generator_path = File.join(spec.full_gem_path, "lib/generators")
+ paths << generator_path if File.exist?(generator_path)
+ end
+ elsif defined?(RAILS_ROOT)
+ paths += Dir[File.join(RAILS_ROOT, "vendor", "gems", "gems", "*", "lib", "generators")]
end
paths
end
- # If RAILS_ROOT is defined, add vendor/gems, vendor/plugins and lib/generators
- # paths.
+ # Load paths from plugin.
#
- def self.rails_root_generators_paths
- paths = []
- if defined?(RAILS_ROOT)
- paths += Dir[File.join(RAILS_ROOT, "vendor", "gems", "gems", "*", "lib", "generators")]
- paths += Dir[File.join(RAILS_ROOT, "vendor", "plugins", "*", "lib", "generators")]
- paths << File.join(RAILS_ROOT, "lib", "generators")
- end
- paths
+ def self.plugins_generators_paths
+ return [] unless defined?(RAILS_ROOT)
+ Dir[File.join(RAILS_ROOT, "vendor", "plugins", "*", "lib", "generators")]
end
# Hold configured generators fallbacks. If a plugin developer wants a
@@ -125,7 +122,7 @@ module Rails
# Rails::Generators.fallbacks[:shoulda] = :test_unit
#
def self.fallbacks
- @@fallbacks ||= {}
+ @fallbacks ||= {}
end
# Remove the color from output.
@@ -143,14 +140,17 @@ module Rails
# 5) rubygems generators
# 6) builtin generators
#
- # TODO Remove hardcoded paths for all, except (1).
+ # TODO Remove hardcoded paths for all, except (6).
#
def self.load_paths
- @@load_paths ||= begin
- paths = self.rails_root_generators_paths
+ @load_paths ||= begin
+ paths = []
+ paths << File.join(RAILS_ROOT, "lib", "generators") if defined?(RAILS_ROOT)
paths << File.join(Thor::Util.user_home, ".rails", "generators")
- paths += self.rubygems_generators_paths
+ paths += self.plugins_generators_paths
+ paths += self.gems_generators_paths
paths << File.expand_path(File.join(File.dirname(__FILE__), "generators"))
+ paths.uniq!
paths
end
end
@@ -279,39 +279,18 @@ module Rails
end
# Receives namespaces in an array and tries to find matching generators
- # in the load path. Each path is traversed into directory lookups. For
- # example:
- #
- # rails:generators:model
- #
- # Becomes:
- #
- # generators/rails/model/model_generator.rb
- # generators/rails/model_generator.rb
- # generators/model_generator.rb
+ # in the load path.
#
def self.lookup(attempts) #:nodoc:
- attempts.each do |attempt|
- generators_path = ['.']
-
- paths = attempt.gsub(':generators:', ':').split(':')
- name = "#{paths.last}_generator.rb"
-
- until paths.empty?
- generators_path.unshift File.join(*paths)
- paths.pop
- end
-
- generators_path.uniq!
- generators_path = "{#{generators_path.join(',')}}"
-
- self.load_paths.each do |path|
- Dir[File.join(path, generators_path, name)].each do |file|
- begin
- require file
- rescue Exception => e
- warn "[WARNING] Could not load generator at #{file.inspect}. Error: #{e.message}"
- end
+ attempts = attempts.map { |a| "#{a.split(":").last}_generator" }.uniq
+ attempts = "{#{attempts.join(',')}}.rb"
+
+ self.load_paths.each do |path|
+ Dir[File.join(path, '**', attempts)].each do |file|
+ begin
+ require file
+ rescue Exception => e
+ warn "[WARNING] Could not load generator at #{file.inspect}. Error: #{e.message}"
end
end
end
diff --git a/railties/lib/generators/actions.rb b/railties/lib/generators/actions.rb
index 03d0d11a07..c4552dd399 100644
--- a/railties/lib/generators/actions.rb
+++ b/railties/lib/generators/actions.rb
@@ -89,13 +89,11 @@ module Rails
# git :add => "onefile.rb", :rm => "badfile.cxx"
#
def git(command={})
- in_root do
- if command.is_a?(Symbol)
- run "git #{command}"
- else
- command.each do |command, options|
- run "git #{command} #{options}"
- end
+ if command.is_a?(Symbol)
+ run "git #{command}"
+ else
+ command.each do |command, options|
+ run "git #{command} #{options}"
end
end
end
diff --git a/railties/lib/generators/active_record.rb b/railties/lib/generators/active_record.rb
index 924b70881a..ff3093f356 100644
--- a/railties/lib/generators/active_record.rb
+++ b/railties/lib/generators/active_record.rb
@@ -1,7 +1,6 @@
require 'generators/named_base'
require 'generators/migration'
require 'generators/active_model'
-require 'active_record'
module ActiveRecord
module Generators
diff --git a/railties/lib/generators/base.rb b/railties/lib/generators/base.rb
index cbe9c0a49d..c5d769b6ed 100644
--- a/railties/lib/generators/base.rb
+++ b/railties/lib/generators/base.rb
@@ -9,6 +9,8 @@ module Rails
include Thor::Actions
include Rails::Generators::Actions
+ add_runtime_options!
+
# Automatically sets the source root based on the class name.
#
def self.source_root
@@ -45,8 +47,10 @@ module Rails
#
# ==== Examples
#
- # class ControllerGenerator < Rails::Generators::Base
- # hook_for :test_framework, :aliases => "-t"
+ # module Rails::Generators
+ # class ControllerGenerator < Base
+ # hook_for :test_framework, :aliases => "-t"
+ # end
# end
#
# The example above will create a test framework option and will invoke
@@ -64,7 +68,49 @@ module Rails
# invoked. This allows any test framework to hook into Rails as long as it
# provides any of the hooks above.
#
- # Finally, if the user don't want to use any test framework, he can do:
+ # ==== Options
+ #
+ # This lookup can be customized with two options: :base and :as. The first
+ # is the root module value and in the example above defaults to "rails".
+ # The later defaults to the generator name, without the "Generator" ending.
+ #
+ # Let's suppose you are creating a generator that needs to invoke the
+ # controller generator from test unit. Your first attempt is:
+ #
+ # class AwesomeGenerator < Rails::Generators::Base
+ # hook_for :test_framework
+ # end
+ #
+ # The lookup in this case for test_unit as input is:
+ #
+ # "test_unit:generators:awesome", "test_unit"
+ #
+ # Which is not the desired the lookup. You can change it by providing the
+ # :as option:
+ #
+ # class AwesomeGenerator < Rails::Generators::Base
+ # hook_for :test_framework, :as => :controller
+ # end
+ #
+ # And now it will lookup at:
+ #
+ # "test_unit:generators:awesome", "test_unit"
+ #
+ # Similarly, if you want it to also lookup in the rails namespace, you just
+ # need to provide the :base value:
+ #
+ # class AwesomeGenerator < Rails::Generators::Base
+ # hook_for :test_framework, :base => :rails, :as => :controller
+ # end
+ #
+ # And the lookup is exactly the same as previously:
+ #
+ # "rails:generators:test_unit", "test_unit:generators:controller", "test_unit"
+ #
+ # ==== Switches
+ #
+ # All hooks come with switches for user interface. If the user don't want
+ # to use any test framework, he can do:
#
# ruby script/generate controller Account --skip-test-framework
#
diff --git a/railties/lib/generators/erb/scaffold/scaffold_generator.rb b/railties/lib/generators/erb/scaffold/scaffold_generator.rb
index 955f22192a..d51dc7d725 100644
--- a/railties/lib/generators/erb/scaffold/scaffold_generator.rb
+++ b/railties/lib/generators/erb/scaffold/scaffold_generator.rb
@@ -1,13 +1,13 @@
require 'generators/erb'
+require 'generators/resource_helpers'
module Erb
module Generators
class ScaffoldGenerator < Base
- include Rails::Generators::ScaffoldBase
+ include Rails::Generators::ResourceHelpers
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
- class_option :form, :type => :boolean
class_option :layout, :type => :boolean
class_option :singleton, :type => :boolean, :desc => "Supply to skip index view"
@@ -33,7 +33,6 @@ module Erb
end
def copy_form_file
- return unless options[:form]
copy_view :_form
end
diff --git a/railties/lib/generators/erb/scaffold/templates/_form.html.erb b/railties/lib/generators/erb/scaffold/templates/_form.html.erb
new file mode 100644
index 0000000000..d02028d983
--- /dev/null
+++ b/railties/lib/generators/erb/scaffold/templates/_form.html.erb
@@ -0,0 +1,17 @@
+<%% form_for(@<%= singular_name %>) do |f| %>
+ <%%= f.error_messages %>
+
+<% for attribute in attributes -%>
+ <div class="field">
+ <%%= f.label :<%= attribute.name %> %><br />
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
+ </div>
+<% end -%>
+ <div class="actions">
+ <%% if @<%= singular_name %>.new_record? %>
+ <%%= f.submit 'Create' %>
+ <%% else %>
+ <%%= f.submit 'Update' %>
+ <%% end %>
+ </div>
+<%% end %>
diff --git a/railties/lib/generators/erb/scaffold/templates/edit.html.erb b/railties/lib/generators/erb/scaffold/templates/edit.html.erb
index cca1d61c68..5bc507ffc8 100644
--- a/railties/lib/generators/erb/scaffold/templates/edit.html.erb
+++ b/railties/lib/generators/erb/scaffold/templates/edit.html.erb
@@ -1,18 +1,6 @@
<h1>Editing <%= singular_name %></h1>
-<%% form_for(@<%= singular_name %>) do |f| %>
- <%%= f.error_messages %>
-
-<% for attribute in attributes -%>
- <p>
- <%%= f.label :<%= attribute.name %> %><br />
- <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
- </p>
-<% end -%>
- <p>
- <%%= f.submit 'Update' %>
- </p>
-<%% end %>
+<%%= render 'form' %>
<%%= link_to 'Show', @<%= singular_name %> %> |
-<%%= link_to 'Back', <%= plural_name %>_path %> \ No newline at end of file
+<%%= link_to 'Back', <%= plural_name %>_path %>
diff --git a/railties/lib/generators/erb/scaffold/templates/layout.html.erb b/railties/lib/generators/erb/scaffold/templates/layout.html.erb
index aacfbe4a8f..6460e5b599 100644
--- a/railties/lib/generators/erb/scaffold/templates/layout.html.erb
+++ b/railties/lib/generators/erb/scaffold/templates/layout.html.erb
@@ -7,7 +7,7 @@
</head>
<body>
-<p style="color: green"><%%= flash[:notice] %></p>
+<p class="notice"><%%= flash[:notice] %></p>
<%%= yield %>
diff --git a/railties/lib/generators/erb/scaffold/templates/new.html.erb b/railties/lib/generators/erb/scaffold/templates/new.html.erb
index 96c89fc50e..9a1c489331 100644
--- a/railties/lib/generators/erb/scaffold/templates/new.html.erb
+++ b/railties/lib/generators/erb/scaffold/templates/new.html.erb
@@ -1,17 +1,5 @@
<h1>New <%= singular_name %></h1>
-<%% form_for(@<%= singular_name %>) do |f| %>
- <%%= f.error_messages %>
+<%%= render 'form' %>
-<% for attribute in attributes -%>
- <p>
- <%%= f.label :<%= attribute.name %> %><br />
- <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
- </p>
-<% end -%>
- <p>
- <%%= f.submit 'Create' %>
- </p>
-<%% end %>
-
-<%%= link_to 'Back', <%= plural_name %>_path %> \ No newline at end of file
+<%%= link_to 'Back', <%= plural_name %>_path %>
diff --git a/railties/lib/generators/named_base.rb b/railties/lib/generators/named_base.rb
index cd7aa61b50..b6ac05f482 100644
--- a/railties/lib/generators/named_base.rb
+++ b/railties/lib/generators/named_base.rb
@@ -97,67 +97,5 @@ module Rails
end
end
end
-
- # Deal with controller names on scaffold. Also provide helpers to deal with
- # ActionORM.
- #
- module ScaffoldBase
- def self.included(base) #:nodoc:
- base.send :attr_reader, :controller_name, :controller_class_name, :controller_file_name,
- :controller_class_path, :controller_file_path
- end
-
- # Set controller variables on initialization.
- #
- def initialize(*args) #:nodoc:
- super
- @controller_name = name.pluralize
-
- base_name, @controller_class_path, @controller_file_path, class_nesting, class_nesting_depth = extract_modules(@controller_name)
- class_name_without_nesting, @controller_file_name, controller_plural_name = inflect_names(base_name)
-
- @controller_class_name = if class_nesting.empty?
- class_name_without_nesting
- else
- "#{class_nesting}::#{class_name_without_nesting}"
- end
- end
-
- protected
-
- # Loads the ORM::Generators::ActiveModel class. This class is responsable
- # to tell scaffold entities how to generate an specific method for the
- # ORM. Check Rails::Generators::ActiveModel for more information.
- #
- def orm_class
- @orm_class ||= begin
- # Raise an error if the class_option :orm was not defined.
- unless self.class.class_options[:orm]
- raise "You need to have :orm as class option to invoke orm_class and orm_instance"
- end
-
- action_orm = "#{options[:orm].to_s.classify}::Generators::ActiveModel"
-
- # If the orm was not loaded, try to load it at "generators/orm",
- # for example "generators/active_record" or "generators/sequel".
- begin
- klass = action_orm.constantize
- rescue NameError
- require "generators/#{options[:orm]}"
- end
-
- # Try once again after loading the file with success.
- klass ||= action_orm.constantize
- rescue Exception => e
- raise Error, "Could not load #{action_orm}, skipping controller. Error: #{e.message}."
- end
- end
-
- # Initialize ORM::Generators::ActiveModel to access instance methods.
- #
- def orm_instance(name=file_name)
- @orm_instance ||= @orm_class.new(name)
- end
- end
end
end
diff --git a/railties/lib/generators/rails/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb
index c80a344e0d..24c9a969f9 100644
--- a/railties/lib/generators/rails/app/app_generator.rb
+++ b/railties/lib/generators/rails/app/app_generator.rb
@@ -4,7 +4,7 @@ require 'rails/version' unless defined?(Rails::VERSION)
module Rails::Generators
class AppGenerator < Base
- DATABASES = %w( mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db )
+ DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
add_shebang_option!
argument :app_path, :type => :string
diff --git a/railties/lib/generators/rails/app/templates/config/databases/sqlite2.yml b/railties/lib/generators/rails/app/templates/config/databases/sqlite2.yml
deleted file mode 100644
index 46f01cb42c..0000000000
--- a/railties/lib/generators/rails/app/templates/config/databases/sqlite2.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-# SQLite version 2.x
-# gem install sqlite-ruby
-development:
- adapter: sqlite
- database: db/development.sqlite2
- pool: 5
-
-# 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: sqlite
- database: db/test.sqlite2
- pool: 5
-
-production:
- adapter: sqlite
- database: db/production.sqlite2
- pool: 5
diff --git a/railties/lib/generators/rails/generator/generator_generator.rb b/railties/lib/generators/rails/generator/generator_generator.rb
index 2fc97b20d3..5b5d1884bc 100644
--- a/railties/lib/generators/rails/generator/generator_generator.rb
+++ b/railties/lib/generators/rails/generator/generator_generator.rb
@@ -6,7 +6,7 @@ module Rails
class_option :namespace, :type => :boolean, :default => true,
:desc => "Namespace generator under lib/generators/name"
- def craete_generator_files
+ def create_generator_files
directory '.', generator_dir
end
diff --git a/railties/lib/generators/rails/resource/resource_generator.rb b/railties/lib/generators/rails/resource/resource_generator.rb
index 70babc0550..9abb8bbeaf 100644
--- a/railties/lib/generators/rails/resource/resource_generator.rb
+++ b/railties/lib/generators/rails/resource/resource_generator.rb
@@ -1,25 +1,19 @@
require 'generators/rails/model/model_generator'
+require 'generators/resource_helpers'
module Rails
module Generators
class ResourceGenerator < ModelGenerator #metagenerator
+ include ResourceHelpers
+
hook_for :resource_controller, :required => true do |base, controller|
- base.invoke controller, [ base.name.pluralize, base.options[:actions] ]
+ base.invoke controller, [ base.controller_name, base.options[:actions] ]
end
class_option :actions, :type => :array, :banner => "ACTION ACTION", :default => [],
:desc => "Actions for the resource controller"
- class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
- class_option :force_plural, :type => :boolean, :desc => "Forces the use of a plural ModelName"
-
- def initialize(*args)
- super
- if name == name.pluralize && !options[:force_plural]
- say "Plural version of the model detected, using singularized version. Override with --force-plural."
- name.replace name.singularize
- end
- end
+ class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
def add_resource_route
route "map.resource#{:s unless options[:singleton]} :#{pluralize?(file_name)}"
diff --git a/railties/lib/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/generators/rails/scaffold/scaffold_generator.rb
index af44c8ba65..fdea5bf52b 100644
--- a/railties/lib/generators/rails/scaffold/scaffold_generator.rb
+++ b/railties/lib/generators/rails/scaffold/scaffold_generator.rb
@@ -3,7 +3,8 @@ require 'generators/rails/resource/resource_generator'
module Rails
module Generators
class ScaffoldGenerator < ResourceGenerator #metagenerator
- remove_hook_for :actions, :resource_controller
+ remove_hook_for :resource_controller
+ remove_class_option :actions
hook_for :scaffold_controller, :required => true
hook_for :stylesheets
diff --git a/railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb b/railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb
index 972be5a33b..228cdecb14 100644
--- a/railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb
+++ b/railties/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb
@@ -1,8 +1,9 @@
+require 'generators/resource_helpers'
+
module Rails
module Generators
class ScaffoldControllerGenerator < NamedBase
- # Add controller methods and ActionORM settings.
- include ScaffoldBase
+ include ResourceHelpers
check_class_collision :suffix => "Controller"
diff --git a/railties/lib/generators/rails/stylesheets/templates/scaffold.css b/railties/lib/generators/rails/stylesheets/templates/scaffold.css
index 093c20994d..d9fa2cf2dc 100644
--- a/railties/lib/generators/rails/stylesheets/templates/scaffold.css
+++ b/railties/lib/generators/rails/stylesheets/templates/scaffold.css
@@ -16,6 +16,14 @@ a { color: #000; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }
+div.field, div.actions {
+ margin-bottom: 10px;
+}
+
+.notice {
+ color: green;
+}
+
.fieldWithErrors {
padding: 2px;
background-color: red;
diff --git a/railties/lib/generators/resource_helpers.rb b/railties/lib/generators/resource_helpers.rb
new file mode 100644
index 0000000000..ba1444652d
--- /dev/null
+++ b/railties/lib/generators/resource_helpers.rb
@@ -0,0 +1,74 @@
+module Rails
+ module Generators
+ # Deal with controller names on scaffold and add some helpers to deal with
+ # ActiveModel.
+ #
+ module ResourceHelpers
+ def self.included(base) #:nodoc:
+ base.send :attr_reader, :controller_name, :controller_class_name, :controller_file_name,
+ :controller_class_path, :controller_file_path
+
+ base.send :class_option, :force_plural, :type => :boolean, :desc => "Forces the use of a plural ModelName"
+ end
+
+ # Set controller variables on initialization.
+ #
+ def initialize(*args) #:nodoc:
+ super
+
+ if name == name.pluralize && !options[:force_plural]
+ say "Plural version of the model detected, using singularized version. Override with --force-plural."
+ name.replace name.singularize
+ assign_names!(self.name)
+ end
+
+ @controller_name = name.pluralize
+
+ base_name, @controller_class_path, @controller_file_path, class_nesting, class_nesting_depth = extract_modules(@controller_name)
+ class_name_without_nesting, @controller_file_name, controller_plural_name = inflect_names(base_name)
+
+ @controller_class_name = if class_nesting.empty?
+ class_name_without_nesting
+ else
+ "#{class_nesting}::#{class_name_without_nesting}"
+ end
+ end
+
+ protected
+
+ # Loads the ORM::Generators::ActiveModel class. This class is responsable
+ # to tell scaffold entities how to generate an specific method for the
+ # ORM. Check Rails::Generators::ActiveModel for more information.
+ #
+ def orm_class
+ @orm_class ||= begin
+ # Raise an error if the class_option :orm was not defined.
+ unless self.class.class_options[:orm]
+ raise "You need to have :orm as class option to invoke orm_class and orm_instance"
+ end
+
+ active_model = "#{options[:orm].to_s.classify}::Generators::ActiveModel"
+
+ # If the orm was not loaded, try to load it at "generators/orm",
+ # for example "generators/active_record" or "generators/sequel".
+ begin
+ klass = active_model.constantize
+ rescue NameError
+ require "generators/#{options[:orm]}"
+ end
+
+ # Try once again after loading the file with success.
+ klass ||= active_model.constantize
+ rescue Exception => e
+ raise Error, "Could not load #{active_model}, skipping controller. Error: #{e.message}."
+ end
+ end
+
+ # Initialize ORM::Generators::ActiveModel to access instance methods.
+ #
+ def orm_instance(name=file_name)
+ @orm_instance ||= @orm_class.new(name)
+ end
+ end
+ end
+end
diff --git a/railties/lib/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/generators/test_unit/scaffold/scaffold_generator.rb
index 78fcea1e9c..a8f9c8bd79 100644
--- a/railties/lib/generators/test_unit/scaffold/scaffold_generator.rb
+++ b/railties/lib/generators/test_unit/scaffold/scaffold_generator.rb
@@ -1,9 +1,10 @@
require 'generators/test_unit'
+require 'generators/resource_helpers'
module TestUnit
module Generators
class ScaffoldGenerator < Base
- include Rails::Generators::ScaffoldBase
+ include Rails::Generators::ResourceHelpers
class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
check_class_collision :suffix => "ControllerTest"
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb
index 49ec5c7fba..1c0af6411a 100644
--- a/railties/lib/rails/plugin.rb
+++ b/railties/lib/rails/plugin.rb
@@ -71,6 +71,10 @@ module Rails
File.exist?(routing_file)
end
+ # Returns true if there is any localization file in locale_path
+ def localized?
+ locale_files.any?
+ end
def view_path
File.join(directory, 'app', 'views')
@@ -87,6 +91,14 @@ module Rails
def routing_file
File.join(directory, 'config', 'routes.rb')
end
+
+ def locale_path
+ File.join(directory, 'config', 'locales')
+ end
+
+ def locale_files
+ Dir[ File.join(locale_path, '*.{rb,yml}') ]
+ end
private
diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb
index 7ea9c7c0f3..0d16cbd7c3 100644
--- a/railties/lib/rails/plugin/loader.rb
+++ b/railties/lib/rails/plugin/loader.rb
@@ -73,6 +73,7 @@ module Rails
def configure_engines
if engines.any?
add_engine_routing_configurations
+ add_engine_locales
add_engine_controller_paths
add_engine_view_paths
end
@@ -84,6 +85,14 @@ module Rails
end
end
+ def add_engine_locales
+ localized_engines = engines.select { |engine| engine.localized? }
+
+ # reverse it such that the last engine can overwrite translations from the first, like with routes
+ locale_files = localized_engines.collect { |engine| engine.locale_files }.reverse.flatten
+ I18n.load_path += locale_files - I18n.load_path
+ end
+
def add_engine_controller_paths
ActionController::Routing.controller_paths += engines.collect {|engine| engine.controller_path }
end
diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake
index b82341ba94..8401cf0590 100644
--- a/railties/lib/tasks/databases.rake
+++ b/railties/lib/tasks/databases.rake
@@ -55,7 +55,7 @@ namespace :db do
case config['adapter']
when 'mysql'
@charset = ENV['CHARSET'] || 'utf8'
- @collation = ENV['COLLATION'] || 'utf8_general_ci'
+ @collation = ENV['COLLATION'] || 'utf8_unicode_ci'
creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)}
begin
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
@@ -292,7 +292,11 @@ namespace :db do
desc "Load a schema.rb file into the database"
task :load => :environment do
file = ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb"
- load(file)
+ if File.exists?(file)
+ load(file)
+ else
+ abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{RAILS_ROOT}/config/environment.rb to prevent active_record from loading: config.frameworks -= [ :active_record ]}
+ end
end
end
diff --git a/railties/lib/vendor/thor-0.11.5/CHANGELOG.rdoc b/railties/lib/vendor/thor-0.11.6/CHANGELOG.rdoc
index dba25b7205..dba25b7205 100644
--- a/railties/lib/vendor/thor-0.11.5/CHANGELOG.rdoc
+++ b/railties/lib/vendor/thor-0.11.6/CHANGELOG.rdoc
diff --git a/railties/lib/vendor/thor-0.11.5/LICENSE b/railties/lib/vendor/thor-0.11.6/LICENSE
index 98722da459..98722da459 100644
--- a/railties/lib/vendor/thor-0.11.5/LICENSE
+++ b/railties/lib/vendor/thor-0.11.6/LICENSE
diff --git a/railties/lib/vendor/thor-0.11.5/README.rdoc b/railties/lib/vendor/thor-0.11.6/README.rdoc
index f1106f02b6..f1106f02b6 100644
--- a/railties/lib/vendor/thor-0.11.5/README.rdoc
+++ b/railties/lib/vendor/thor-0.11.6/README.rdoc
diff --git a/railties/lib/vendor/thor-0.11.5/bin/rake2thor b/railties/lib/vendor/thor-0.11.6/bin/rake2thor
index 50c7410d80..50c7410d80 100755
--- a/railties/lib/vendor/thor-0.11.5/bin/rake2thor
+++ b/railties/lib/vendor/thor-0.11.6/bin/rake2thor
diff --git a/railties/lib/vendor/thor-0.11.5/bin/thor b/railties/lib/vendor/thor-0.11.6/bin/thor
index eaf849fb4a..eaf849fb4a 100755
--- a/railties/lib/vendor/thor-0.11.5/bin/thor
+++ b/railties/lib/vendor/thor-0.11.6/bin/thor
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor.rb b/railties/lib/vendor/thor-0.11.6/lib/thor.rb
index 8dfcfd4c5b..3b45c4e9b7 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor.rb
@@ -135,7 +135,7 @@ class Thor
args, opts = given_args, {}
end
- task ||= Task.dynamic(meth)
+ task ||= Thor::Task::Dynamic.new(meth)
trailing = args[Range.new(arguments.size, -1)]
new(args, opts, config).invoke(task, trailing || [])
end
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/actions.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/actions.rb
index 1d09dc38ae..d561ccb2aa 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/actions.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/actions.rb
@@ -8,23 +8,8 @@ class Thor
module Actions
attr_accessor :behavior
- # On inclusion, add some options to base.
- #
def self.included(base) #:nodoc:
base.extend ClassMethods
- return unless base.respond_to?(:class_option)
-
- base.class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime,
- :desc => "Run but do not make any changes"
-
- base.class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime,
- :desc => "Overwrite files that already exist"
-
- base.class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime,
- :desc => "Skip files that already exist"
-
- base.class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime,
- :desc => "Supress status output"
end
module ClassMethods
@@ -49,6 +34,22 @@ class Thor
paths += from_superclass(:source_paths, [])
paths
end
+
+ # Add runtime options that help actions execution.
+ #
+ def add_runtime_options!
+ class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime,
+ :desc => "Run but do not make any changes"
+
+ class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime,
+ :desc => "Overwrite files that already exist"
+
+ class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime,
+ :desc => "Skip files that already exist"
+
+ class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime,
+ :desc => "Supress status output"
+ end
end
# Extends initializer to add more configuration options.
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/create_file.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/create_file.rb
index 8f6badee27..8f6badee27 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/create_file.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/create_file.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/directory.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/directory.rb
index be5eb822ac..be5eb822ac 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/directory.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/directory.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/empty_directory.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/empty_directory.rb
index 03c1fe4af1..03c1fe4af1 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/empty_directory.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/empty_directory.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/file_manipulation.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/file_manipulation.rb
index 74c157ba8c..d77d90d448 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/file_manipulation.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/file_manipulation.rb
@@ -100,7 +100,7 @@ class Thor
FileUtils.chmod_R(mode, path) unless options[:pretend]
end
- # Prepend text to a file.
+ # Prepend text to a file. Since it depends on inject_into_file, it's reversible.
#
# ==== Parameters
# path<String>:: path of the file to be changed
@@ -111,19 +111,17 @@ class Thor
#
# prepend_file 'config/environments/test.rb', 'config.gem "rspec"'
#
- def prepend_file(path, data=nil, config={}, &block)
- return unless behavior == :invoke
- path = File.expand_path(path, destination_root)
- say_status :prepend, relative_to_original_destination_root(path), config.fetch(:verbose, true)
-
- unless options[:pretend]
- content = data || block.call
- content << File.read(path)
- File.open(path, 'wb') { |file| file.write(content) }
- end
+ # prepend_file 'config/environments/test.rb' do
+ # 'config.gem "rspec"'
+ # end
+ #
+ def prepend_file(path, *args, &block)
+ config = args.last.is_a?(Hash) ? args.pop : {}
+ config.merge!(:after => /\A/)
+ inject_into_file(path, *(args << config), &block)
end
- # Append text to a file.
+ # Append text to a file. Since it depends on inject_into_file, it's reversible.
#
# ==== Parameters
# path<String>:: path of the file to be changed
@@ -134,11 +132,37 @@ class Thor
#
# append_file 'config/environments/test.rb', 'config.gem "rspec"'
#
- def append_file(path, data=nil, config={}, &block)
- return unless behavior == :invoke
- path = File.expand_path(path, destination_root)
- say_status :append, relative_to_original_destination_root(path), config.fetch(:verbose, true)
- File.open(path, 'ab') { |file| file.write(data || block.call) } unless options[:pretend]
+ # append_file 'config/environments/test.rb' do
+ # 'config.gem "rspec"'
+ # end
+ #
+ def append_file(path, *args, &block)
+ config = args.last.is_a?(Hash) ? args.pop : {}
+ config.merge!(:before => /\z/)
+ inject_into_file(path, *(args << config), &block)
+ end
+
+ # Injects text right after the class definition. Since it depends on
+ # inject_into_file, it's reversible.
+ #
+ # ==== Parameters
+ # path<String>:: path of the file to be changed
+ # klass<String|Class>:: the class to be manipulated
+ # data<String>:: the data to append to the class, can be also given as a block.
+ # config<Hash>:: give :verbose => false to not log the status.
+ #
+ # ==== Examples
+ #
+ # inject_into_class "app/controllers/application_controller.rb", " filter_parameter :password\n"
+ #
+ # inject_into_class "app/controllers/application_controller.rb", ApplicationController do
+ # " filter_parameter :password\n"
+ # end
+ #
+ def inject_into_class(path, klass, *args, &block)
+ config = args.last.is_a?(Hash) ? args.pop : {}
+ config.merge!(:after => /class #{klass}\n|class #{klass} .*\n/)
+ inject_into_file(path, *(args << config), &block)
end
# Run a regular expression replacement on a file.
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/inject_into_file.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/inject_into_file.rb
index 66dd1f5fc1..0636ec6591 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/actions/inject_into_file.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/actions/inject_into_file.rb
@@ -3,10 +3,8 @@ require 'thor/actions/empty_directory'
class Thor
module Actions
- # Injects the given content into a file. Different from append_file,
- # prepend_file and gsub_file, this method is reversible. By this reason,
- # the flag can only be strings. gsub_file is your friend if you need to
- # deal with more complex cases.
+ # Injects the given content into a file. Different from gsub_file, this
+ # method is reversible.
#
# ==== Parameters
# destination<String>:: Relative path to the destination root
@@ -16,11 +14,11 @@ class Thor
#
# ==== Examples
#
- # inject_into_file "config/environment.rb", "config.gem thor", :after => "Rails::Initializer.run do |config|\n"
+ # inject_into_file "config/environment.rb", "config.gem :thor", :after => "Rails::Initializer.run do |config|\n"
#
# inject_into_file "config/environment.rb", :after => "Rails::Initializer.run do |config|\n" do
# gems = ask "Which gems would you like to add?"
- # gems.split(" ").map{ |gem| " config.gem #{gem}" }.join("\n")
+ # gems.split(" ").map{ |gem| " config.gem :#{gem}" }.join("\n")
# end
#
def inject_into_file(destination, *args, &block)
@@ -29,40 +27,65 @@ class Thor
else
data, config = args.shift, args.shift
end
-
- log_status = args.empty? || args.pop
action InjectIntoFile.new(self, destination, data, config)
end
class InjectIntoFile < EmptyDirectory #:nodoc:
- attr_reader :flag, :replacement
+ attr_reader :replacement, :flag, :behavior
def initialize(base, destination, data, config)
super(base, destination, { :verbose => true }.merge(config))
- data = data.call if data.is_a?(Proc)
-
- @replacement = if @config.key?(:after)
- @flag = @config.delete(:after)
- @flag + data
+ @behavior, @flag = if @config.key?(:after)
+ [:after, @config.delete(:after)]
else
- @flag = @config.delete(:before)
- data + @flag
+ [:before, @config.delete(:before)]
end
+
+ @replacement = data.is_a?(Proc) ? data.call : data
+ @flag = Regexp.escape(@flag) unless @flag.is_a?(Regexp)
end
def invoke!
- say_status :inject, config[:verbose]
- replace!(flag, replacement)
+ say_status :invoke
+
+ content = if @behavior == :after
+ '\0' + replacement
+ else
+ replacement + '\0'
+ end
+
+ replace!(/#{flag}/, content)
end
def revoke!
- say_status :deinject, config[:verbose]
- replace!(replacement, flag)
+ say_status :revoke
+
+ regexp = if @behavior == :after
+ content = '\1\2'
+ /(#{flag})(.*)(#{Regexp.escape(replacement)})/m
+ else
+ content = '\2\3'
+ /(#{Regexp.escape(replacement)})(.*)(#{flag})/m
+ end
+
+ replace!(regexp, content)
end
protected
+ def say_status(behavior)
+ status = if flag == /\A/
+ behavior == :invoke ? :prepend : :unprepend
+ elsif flag == /\z/
+ behavior == :invoke ? :append : :unappend
+ else
+ behavior == :invoke ? :inject : :deinject
+ end
+
+ super(status, config[:verbose])
+ end
+
# Adds the content to the file.
#
def replace!(regexp, string)
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/base.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/base.rb
index 0fa87f8162..700d794123 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/base.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/base.rb
@@ -355,6 +355,7 @@ class Thor
else
config[:shell].error e.message
end
+ exit(1) if exit_on_failure?
end
protected
@@ -491,6 +492,12 @@ class Thor
end
end
+ # A flag that makes the process exit with status 1 if any error happens.
+ #
+ def exit_on_failure?
+ false
+ end
+
# SIGNATURE: Sets the baseclass. This is where the superclass lookup
# finishes.
def baseclass #:nodoc:
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/hash_with_indifferent_access.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/core_ext/hash_with_indifferent_access.rb
index 78bc5cf4bf..78bc5cf4bf 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/hash_with_indifferent_access.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/core_ext/hash_with_indifferent_access.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/ordered_hash.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/core_ext/ordered_hash.rb
index 27fea5bb35..27fea5bb35 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/core_ext/ordered_hash.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/core_ext/ordered_hash.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/error.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/error.rb
index f9b31a35d1..f9b31a35d1 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/error.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/error.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/group.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/group.rb
index 1e59df2313..1e59df2313 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/group.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/group.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/invocation.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/invocation.rb
index c0388dd863..32e6a72454 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/invocation.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/invocation.rb
@@ -153,7 +153,7 @@ class Thor
raise "Expected Thor class, got #{klass}" unless klass <= Thor::Base
task ||= klass.default_task if klass <= Thor
- task = klass.all_tasks[task.to_s] || Task.dynamic(task) if task && !task.is_a?(Thor::Task)
+ task = klass.all_tasks[task.to_s] || Thor::Task::Dynamic.new(task) if task && !task.is_a?(Thor::Task)
task
end
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/parser.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/parser.rb
index 57a3f6e1a5..57a3f6e1a5 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/parser.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/parser.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/argument.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/argument.rb
index aa8ace4719..aa8ace4719 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/argument.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/argument.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/arguments.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/arguments.rb
index fb5d965e06..fb5d965e06 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/arguments.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/arguments.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/option.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/option.rb
index 9e40ec73fa..9e40ec73fa 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/option.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/option.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/options.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/options.rb
index 75092308b5..75092308b5 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/parser/options.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/parser/options.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/rake_compat.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/rake_compat.rb
index 3ab6bb21f5..3ab6bb21f5 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/rake_compat.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/rake_compat.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/runner.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/runner.rb
index 3639ac0aa9..43da09b336 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/runner.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/runner.rb
@@ -175,6 +175,10 @@ class Thor::Runner < Thor #:nodoc:
File.open(yaml_file, "w") { |f| f.puts yaml.to_yaml }
end
+ def self.exit_on_failure?
+ true
+ end
+
# Load the thorfiles. If relevant_to is supplied, looks for specific files
# in the thor_root instead of loading them all.
#
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/shell.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/shell.rb
index 0d3f4d5951..0d3f4d5951 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/shell.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/shell.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/shell/basic.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/shell/basic.rb
index 3c02e47c33..ea9665380b 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/shell/basic.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/shell/basic.rb
@@ -34,12 +34,11 @@ class Thor
# ==== Example
# say("I know you knew that.")
#
- def say(message="", color=nil, force_new_line=false)
+ def say(message="", color=nil, force_new_line=(message.to_s !~ /( |\t)$/))
message = message.to_s
- new_line = force_new_line || !(message[-1, 1] == " " || message[-1, 1] == "\t")
message = set_color(message, color) if color
- if new_line
+ if force_new_line
$stdout.puts(message)
else
$stdout.print(message)
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/shell/color.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/shell/color.rb
index 24704f7885..24704f7885 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/shell/color.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/shell/color.rb
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/task.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/task.rb
index 23d35b883c..91c7564d3f 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/task.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/task.rb
@@ -1,11 +1,19 @@
class Thor
class Task < Struct.new(:name, :description, :usage, :options)
- # Creates a dynamic task. Dynamic tasks are created on demand to allow method
- # missing calls (since a method missing does not have a task object for it).
+ # A dynamic task that handles method missing scenarios.
#
- def self.dynamic(name)
- new(name, "A dynamically-generated task", name.to_s)
+ class Dynamic < Task
+ def initialize(name)
+ super(name.to_s, "A dynamically-generated task", name.to_s)
+ end
+
+ def run(instance, args=[])
+ unless (instance.methods & [name.to_s, name.to_sym]).empty?
+ raise Error, "could not find Thor class or task '#{name}'"
+ end
+ super
+ end
end
def initialize(name, description, usage, options=nil)
@@ -37,8 +45,6 @@ class Thor
# injected in the usage.
#
def formatted_usage(klass=nil, namespace=false, show_options=true)
- formatted = ''
-
formatted = if namespace.is_a?(String)
"#{namespace}:"
elsif klass && namespace
@@ -77,7 +83,7 @@ class Thor
#
def public_method?(instance) #:nodoc:
collection = instance.private_methods + instance.protected_methods
- !(collection).include?(name.to_s) && !(collection).include?(name.to_sym) # For Ruby 1.9
+ (collection & [name.to_s, name.to_sym]).empty?
end
# Clean everything that comes from the Thor gempath and remove the caller.
diff --git a/railties/lib/vendor/thor-0.11.5/lib/thor/util.rb b/railties/lib/vendor/thor-0.11.6/lib/thor/util.rb
index 4938dc4aca..fd820d7462 100644
--- a/railties/lib/vendor/thor-0.11.5/lib/thor/util.rb
+++ b/railties/lib/vendor/thor-0.11.6/lib/thor/util.rb
@@ -22,7 +22,7 @@ class Thor
# namespace<String>:: The namespace to search for.
#
def self.find_by_namespace(namespace)
- namespace = 'default' if namespace.empty?
+ namespace = "default#{namespace}" if namespace.empty? || namespace =~ /^:/
Thor::Base.subclasses.find do |klass|
klass.namespace == namespace
@@ -137,17 +137,18 @@ class Thor
# inherit from Thor or Thor::Group.
#
def self.namespace_to_thor_class_and_task(namespace, raise_if_nil=true)
- klass, task_name = Thor::Util.find_by_namespace(namespace), nil
+ if namespace.include?(?:)
+ pieces = namespace.split(":")
+ task = pieces.pop
+ klass = Thor::Util.find_by_namespace(pieces.join(":"))
+ end
- if klass.nil? && namespace.include?(?:)
- namespace = namespace.split(":")
- task_name = namespace.pop
- klass = Thor::Util.find_by_namespace(namespace.join(":"))
+ unless klass
+ klass, task = Thor::Util.find_by_namespace(namespace), nil
end
raise Error, "could not find Thor class or task '#{namespace}'" if raise_if_nil && klass.nil?
-
- return klass, task_name
+ return klass, task
end
# Receives a path and load the thor file in the path. The file is evaluated
diff --git a/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml b/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml
new file mode 100644
index 0000000000..641a7e035c
--- /dev/null
+++ b/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml
@@ -0,0 +1,2 @@
+en:
+ hello: "Hello from Engine"
diff --git a/railties/test/fixtures/vendor/another_gem_path/xspec/lib/generators/xspec_generator.rb b/railties/test/fixtures/vendor/another_gem_path/xspec/lib/generators/xspec_generator.rb
new file mode 100644
index 0000000000..cd477eb4c9
--- /dev/null
+++ b/railties/test/fixtures/vendor/another_gem_path/xspec/lib/generators/xspec_generator.rb
@@ -0,0 +1,2 @@
+class XspecGenerator < Rails::Generators::NamedBase
+end
diff --git a/railties/test/fixtures/vendor/gems/gems/mspec/lib/generators/mspec_generator.rb b/railties/test/fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb
index 191bdbf2fc..191bdbf2fc 100644
--- a/railties/test/fixtures/vendor/gems/gems/mspec/lib/generators/mspec_generator.rb
+++ b/railties/test/fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb
diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb
index 9444a9ed4b..a258574dce 100644
--- a/railties/test/generators/generators_test_helper.rb
+++ b/railties/test/generators/generators_test_helper.rb
@@ -8,9 +8,12 @@ else
RAILS_ROOT = fixtures
end
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activerecord/lib"
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activerecord/lib"
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../actionpack/lib"
require 'generators'
+require 'activerecord'
+require 'action_dispatch'
CURRENT_PATH = File.expand_path(Dir.pwd)
Rails::Generators.no_color!
@@ -19,7 +22,7 @@ class GeneratorsTestCase < Test::Unit::TestCase
include FileUtils
def destination_root
- @destination_root ||= File.expand_path(File.join(File.dirname(__FILE__),
+ @destination_root ||= File.expand_path(File.join(File.dirname(__FILE__),
'..', 'fixtures', 'tmp'))
end
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index 05eadd3460..63559a8a01 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -75,6 +75,7 @@ class ScaffoldGeneratorTest < GeneratorsTestCase
edit
new
show
+ _form
).each { |view| assert_file "app/views/product_lines/#{view}.html.erb" }
assert_file "app/views/layouts/product_lines.html.erb"
diff --git a/railties/test/generators/session_migration_generator_test.rb b/railties/test/generators/session_migration_generator_test.rb
index 57bd755a9a..293b903b87 100644
--- a/railties/test/generators/session_migration_generator_test.rb
+++ b/railties/test/generators/session_migration_generator_test.rb
@@ -2,16 +2,6 @@ require 'abstract_unit'
require 'generators/generators_test_helper'
require 'generators/rails/session_migration/session_migration_generator'
-module ActiveRecord
- module SessionStore
- class Session
- class << self
- attr_accessor :table_name
- end
- end
- end
-end
-
class SessionMigrationGeneratorTest < GeneratorsTestCase
def test_session_migration_with_default_name
@@ -31,7 +21,10 @@ class SessionMigrationGeneratorTest < GeneratorsTestCase
assert_match /class AddSessionsTable < ActiveRecord::Migration/, migration
assert_match /create_table :custom_table_name/, migration
end
+ ensure
+ ActiveRecord::SessionStore::Session.table_name = "sessions"
end
+
protected
def run_generator(args=[])
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index 89d52dd170..4cc0b33521 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -4,6 +4,11 @@ require 'generators/test_unit/model/model_generator'
require 'mocha'
class GeneratorsTest < GeneratorsTestCase
+ def setup
+ Rails::Generators.instance_variable_set(:@load_paths, nil)
+ Gem.stubs(:respond_to?).with(:loaded_specs).returns(false)
+ end
+
def test_invoke_when_generator_is_not_found
output = capture(:stdout){ Rails::Generators.invoke :unknown }
assert_equal "Could not find generator unknown.\n", output
@@ -70,6 +75,20 @@ class GeneratorsTest < GeneratorsTestCase
assert_equal "mspec", klass.namespace
end
+ def test_find_by_namespace_lookup_with_gem_specification
+ assert_nil Rails::Generators.find_by_namespace(:xspec)
+ Rails::Generators.instance_variable_set(:@load_paths, nil)
+
+ spec = Gem::Specification.new
+ spec.expects(:full_gem_path).returns(File.join(RAILS_ROOT, 'vendor', 'another_gem_path', 'xspec'))
+ Gem.expects(:respond_to?).with(:loaded_specs).returns(true)
+ Gem.expects(:loaded_specs).returns(:spec => spec)
+
+ klass = Rails::Generators.find_by_namespace(:xspec)
+ assert klass
+ assert_equal "xspec", klass.namespace
+ end
+
def test_builtin_generators
assert Rails::Generators.builtin.include? %w(rails model)
end
diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb
index 1fecd62995..5bbd060962 100644
--- a/railties/test/initializer_test.rb
+++ b/railties/test/initializer_test.rb
@@ -406,6 +406,7 @@ class InitializerSetupI18nTests < Test::Unit::TestCase
File.expand_path(File.dirname(__FILE__) + "/../../actionpack/lib/action_view/locale/en.yml"),
File.expand_path(File.dirname(__FILE__) + "/../../activemodel/lib/active_model/locale/en.yml"),
File.expand_path(File.dirname(__FILE__) + "/../../activerecord/lib/active_record/locale/en.yml"),
+ File.expand_path(File.dirname(__FILE__) + "/../../railties/test/fixtures/plugins/engines/engine/config/locales/en.yml"),
"my/test/locale.yml",
"my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /\.\./ ? File.expand_path(path) : path }
end
diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb
index 873e000222..99301347b6 100644
--- a/railties/test/plugin_loader_test.rb
+++ b/railties/test/plugin_loader_test.rb
@@ -156,6 +156,14 @@ class TestPluginLoader < Test::Unit::TestCase
plugin_load_paths.each { |path| assert $LOAD_PATH.include?(path) }
end
+ def test_should_add_locale_files_to_I18n_load_path
+ only_load_the_following_plugins! [:engine]
+
+ @loader.send :add_engine_locales
+
+ assert I18n.load_path.include?(File.join(plugin_fixture_path('engines/engine'), 'config', 'locales', 'en.yml'))
+ end
+
private
def reset_load_path!