aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/lib/rails/application.rb18
-rw-r--r--railties/lib/rails/engine.rb9
-rw-r--r--railties/test/railties/engine_test.rb25
3 files changed, 46 insertions, 6 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 7c590b701e..c403863007 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -145,9 +145,25 @@ module Rails
protected
+ def static_paths
+ @static_paths ||= begin
+ static_paths = ActiveSupport::OrderedHash.new
+ static_paths["/"] = paths.public.to_a.first
+
+ railties.all do |railtie|
+ if railtie.config.respond_to?(:asset_path) && railtie.config.asset_path
+ public_path = railtie.config.paths.public.to_a.first
+ static_paths[railtie.config.asset_path % ""] = public_path if File.exists?(public_path)
+ end
+ end
+
+ static_paths
+ end
+ end
+
def default_middleware_stack
ActionDispatch::MiddlewareStack.new.tap do |middleware|
- middleware.use ::ActionDispatch::Static, paths.public.to_a.first if config.serve_static_assets
+ middleware.use ::ActionDispatch::Static, static_paths if config.serve_static_assets
middleware.use ::Rack::Lock if !config.allow_concurrency
middleware.use ::Rack::Runtime
middleware.use ::Rails::Rack::Logger
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 49553a57f3..85ff09d2af 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -256,11 +256,7 @@ module Rails
end
def config
- @config ||= begin
- config = Engine::Configuration.new(find_root_with_flag("lib"))
- config.asset_path = "/#{engine_name}%s" if File.exists?(config.paths.public.to_a.first)
- config
- end
+ @config ||= Engine::Configuration.new(find_root_with_flag("lib"))
end
# Add configured load paths to ruby load paths and remove duplicates.
@@ -335,6 +331,9 @@ module Rails
require environment if environment
end
+ initializer :default_asset_path do
+ config.asset_path = "/#{engine_name}%s" unless config.asset_path
+ end
protected
def find_root_with_flag(flag, default=nil)
root_path = self.class.called_from
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index 788bc77620..d4ecdf4742 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -273,5 +273,30 @@ module RailtiesTest
"<link href=\"/omg/bukkits/stylesheets/foo.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
assert_equal expected, stripped_body
end
+
+ test "engine's files are served via ActionDispatch::Static" do
+ add_to_config "config.serve_static_assets = true"
+
+ @plugin.write "lib/bukkits.rb", <<-RUBY
+ class Bukkits
+ class Engine < ::Rails::Engine
+ engine_name :bukkits
+ end
+ end
+ RUBY
+
+ @plugin.write "public/bukkits.html", "/bukkits/bukkits.html"
+ app_file "public/app.html", "/app.html"
+
+ boot_rails
+
+ env = Rack::MockRequest.env_for("/app.html")
+ response = Rails.application.call(env)
+ assert_equal response[2].path, File.join(app_path, "public/app.html")
+
+ env = Rack::MockRequest.env_for("/bukkits/bukkits.html")
+ response = Rails.application.call(env)
+ assert_equal response[2].path, File.join(@plugin.path, "public/bukkits.html")
+ end
end
end