Permalink
Browse files

Engine can now load its own plugins

  • Loading branch information...
1 parent ad6be08 commit c787bfdf932450c5fd4c0df805454aa40a388117 @drogus drogus committed Jun 23, 2010
@@ -10,7 +10,7 @@ class Configuration < ::Rails::Engine::Configuration
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 @@ def paths
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 " <<
@@ -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 @@ def engines
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
@@ -2,6 +2,7 @@
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 @@ def eager_load!
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)
@@ -5,7 +5,7 @@ class Engine
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 @@ def paths
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
@@ -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
@@ -85,5 +85,23 @@ class Engine < ::Rails::Engine
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

0 comments on commit c787bfd

Please sign in to comment.