diff options
author | José Valim and Mikel Lindsaar <pair@programming.com> | 2010-01-25 09:50:01 +1100 |
---|---|---|
committer | José Valim and Mikel Lindsaar <pair@programming.com> | 2010-01-25 09:50:01 +1100 |
commit | 4e96442c4e404141830b2d7f0d850b6556190b39 (patch) | |
tree | a3ca088ad9d68b5be9ace4d431375bb3fd4ea045 /railties/lib/rails/plugin.rb | |
parent | a74a655648618a6ed568b9b4ef3a17a8970e7774 (diff) | |
parent | 396003fc48d7c0ba206ad059646c7414bee22a36 (diff) | |
download | rails-4e96442c4e404141830b2d7f0d850b6556190b39.tar.gz rails-4e96442c4e404141830b2d7f0d850b6556190b39.tar.bz2 rails-4e96442c4e404141830b2d7f0d850b6556190b39.zip |
Merge branch 'master' of git://github.com/rails/rails
Conflicts:
actionmailer/lib/action_mailer/mail_helper.rb
railties/lib/rails/configuration.rb
Diffstat (limited to 'railties/lib/rails/plugin.rb')
-rw-r--r-- | railties/lib/rails/plugin.rb | 63 |
1 files changed, 26 insertions, 37 deletions
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index c3b81bcd3e..4c73809177 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -1,5 +1,11 @@ +require 'rails/engine' + module Rails - class Plugin < Railtie + class Plugin < Engine + def self.inherited(base) + raise "You cannot inherit from Rails::Plugin" + end + def self.all(list, paths) plugins = [] paths.each do |path| @@ -17,52 +23,35 @@ module Rails attr_reader :name, :path - def initialize(path) - @name = File.basename(path).to_sym - @path = path - end + def load_tasks + super + extra_tasks = Dir["#{root}/{tasks,rails/tasks}/**/*.rake"] - def load_paths - Dir["#{path}/{lib}", "#{path}/app/{models,controllers,helpers}"] + unless extra_tasks.empty? + ActiveSupport::Deprecation.warn "Having rake tasks in PLUGIN_PATH/tasks or " << + "PLUGIN_PATH/rails/tasks is deprecated. Use to PLUGIN_PATH/lib/tasks instead" + extra_tasks.sort.each { |ext| load(ext) } + end end - def load_tasks - Dir["#{path}/{tasks,lib/tasks,rails/tasks}/**/*.rake"].sort.each { |ext| load ext } + def initialize(root) + @name = File.basename(root).to_sym + config.root = root end - initializer :add_to_load_path, :after => :set_autoload_paths do |app| - load_paths.each do |path| - $LOAD_PATH << path - require "active_support/dependencies" - - ActiveSupport::Dependencies.load_paths << path - - unless app.config.reload_plugins - ActiveSupport::Dependencies.load_once_paths << path - end - end + def config + @config ||= Engine::Configuration.new end - initializer :load_init_rb, :before => :load_application_initializers do |app| - file = "#{@path}/init.rb" + initializer :load_init_rb do |app| + file = Dir["#{root}/{rails/init,init}.rb"].first config = app.config - eval File.read(file), binding, file if File.file?(file) - end - - initializer :add_view_paths, :after => :initialize_framework_views do - plugin_views = "#{path}/app/views" - if File.directory?(plugin_views) - ActionController::Base.view_paths.concat([plugin_views]) if defined? ActionController - ActionMailer::Base.view_paths.concat([plugin_views]) if defined? ActionMailer - end + eval(File.read(file), binding, file) if file && File.file?(file) end - # TODO Isn't it supposed to be :after => "action_controller.initialize_routing" ? - initializer :add_routing_file, :after => :initialize_routing do |app| - routing_file = "#{path}/config/routes.rb" - if File.exist?(routing_file) - app.route_configuration_files << routing_file - app.reload_routes! + initializer :sanity_check_railties_collision do + if Engine.subclasses.map { |k| k.root.to_s }.include?(root.to_s) + raise "\"#{name}\" is a Railtie/Engine and cannot be installed as plugin" end end end |