diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-06-23 16:10:26 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-09-03 22:59:03 +0200 |
commit | c787bfdf932450c5fd4c0df805454aa40a388117 (patch) | |
tree | 624f3b8acc1cbd499f6210a184aa8dfc62015dbd /railties | |
parent | ad6be0876271f86e76c89645a0106b85c9d77ad7 (diff) | |
download | rails-c787bfdf932450c5fd4c0df805454aa40a388117.tar.gz rails-c787bfdf932450c5fd4c0df805454aa40a388117.tar.bz2 rails-c787bfdf932450c5fd4c0df805454aa40a388117.zip |
Engine can now load its own plugins
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/application/railties.rb | 24 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails/engine/configuration.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/engine/railties.rb | 23 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 18 |
6 files changed, 62 insertions, 16 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index a28fc62ccd..a20208f8d5 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -10,7 +10,7 @@ module Rails attr_accessor :allow_concurrency, :cache_classes, :cache_store, :encoding, :consider_all_requests_local, :dependency_loading, :filter_parameters, :log_level, :logger, - :plugins, :preload_frameworks, :reload_plugins, + :preload_frameworks, :reload_plugins, :secret_token, :serve_static_assets, :session_options, :time_zone, :whiny_nils @@ -53,8 +53,6 @@ module Rails paths.log "log/#{Rails.env}.log" paths.tmp "tmp" paths.tmp.cache "tmp/cache" - paths.vendor "vendor", :load_path => true - paths.vendor.plugins "vendor/plugins" if File.exists?("#{root}/test/mocks/#{Rails.env}") ActiveSupport::Deprecation.warn "\"Rails.root/test/mocks/#{Rails.env}\" won't be added " << diff --git a/railties/lib/rails/application/railties.rb b/railties/lib/rails/application/railties.rb index 14ba0afc7c..2b3783e998 100644 --- a/railties/lib/rails/application/railties.rb +++ b/railties/lib/rails/application/railties.rb @@ -1,13 +1,10 @@ -module Rails - class Application - class Railties - # TODO Write tests for this behavior extracted from Application - def initialize(config) - @config = config - end +require 'rails/engine/railties' +module Rails + class Application < Engine + class Railties < Rails::Engine::Railties def all(&block) - @all ||= railties + engines + plugins + @all ||= railties + engines + super @all.each(&block) if block @all end @@ -21,10 +18,13 @@ module Rails end def plugins - @plugins ||= begin - plugin_names = (@config.plugins || [:all]).map { |p| p.to_sym } - Plugin.all(plugin_names, @config.paths.vendor.plugins) - end + @plugins ||= super + plugins_for_engines + end + + def plugins_for_engines + engines.map { |e| + e.railties.plugins + }.flatten end end end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index f8a33ffe24..385e3439f1 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -2,6 +2,7 @@ require 'rails/railtie' require 'active_support/core_ext/module/delegation' require 'pathname' require 'rbconfig' +require 'rails/engine/railties' module Rails # Rails::Engine allows you to wrap a specific Rails application and share it accross @@ -140,6 +141,10 @@ module Rails end end + def railties + @railties ||= Railties.new(config) + end + def app raise "You can't use Engine as rack application without providing valid rack endpoint" unless endpoint @app ||= config.middleware.build(endpoint) diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index 9a9ec8b3ad..0c91796fc9 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -5,7 +5,7 @@ module Rails class Configuration < ::Rails::Railtie::Configuration attr_reader :root attr_writer :eager_load_paths, :autoload_once_paths, :autoload_paths - attr_accessor :middleware + attr_accessor :middleware, :plugins def initialize(root=nil) super() @@ -31,6 +31,8 @@ module Rails paths.public "public" paths.public.javascripts "public/javascripts" paths.public.stylesheets "public/stylesheets" + paths.vendor "vendor", :load_path => true + paths.vendor.plugins "vendor/plugins" paths end end diff --git a/railties/lib/rails/engine/railties.rb b/railties/lib/rails/engine/railties.rb new file mode 100644 index 0000000000..389a7602c6 --- /dev/null +++ b/railties/lib/rails/engine/railties.rb @@ -0,0 +1,23 @@ +module Rails + class Engine < Railtie + class Railties + # TODO Write tests for this behavior extracted from Application + def initialize(config) + @config = config + end + + def all(&block) + @all ||= plugins + @all.each(&block) if block + @all + end + + def plugins + @plugins ||= begin + plugin_names = (@config.plugins || [:all]).map { |p| p.to_sym } + Plugin.all(plugin_names, @config.paths.vendor.plugins) + end + end + end + end +end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 08ba308bc4..a0028c1d70 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -85,5 +85,23 @@ module RailtiesTest assert_equal "HELLO WORLD", response[2] end + + test "engine can load its own plugins" do + @plugin.write "lib/bukkits.rb", <<-RUBY + class Bukkits + class Engine < ::Rails::Engine + config.paths.vendor.plugins = "#{File.join(@plugin.path, "lib/bukkits/plugins")}" + end + end + RUBY + + @plugin.write "lib/bukkits/plugins/yaffle/init.rb", <<-RUBY + Bukkits::Engine.config.yaffle_loaded = true + RUBY + + boot_rails + + assert Bukkits::Engine.config.yaffle_loaded + end end end |