Get rid of static_paths method and instead configure paths for ActionDispatch::Static in initializers

This commit is contained in:
Piotr Sarnacki
2010-08-04 22:22:06 +02:00
parent d812677277
commit 8284fd3855
6 changed files with 29 additions and 17 deletions

View File

@@ -145,25 +145,9 @@ 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, static_paths if config.serve_static_assets
middleware.use ::ActionDispatch::Static, config.static_asset_paths if config.serve_static_assets
middleware.use ::Rack::Lock if !config.allow_concurrency
middleware.use ::Rack::Runtime
middleware.use ::Rails::Rack::Logger

View File

@@ -37,6 +37,10 @@ module Rails
super(value)
end
def compiled_asset_path
"/"
end
def encoding=(value)
@encoding = value
if "ruby".encoding_aware?

View File

@@ -428,6 +428,13 @@ module Rails
initializer :default_asset_path do
config.asset_path = "/#{engine_name}%s" unless config.asset_path
end
initializer :append_asset_paths do
public_path = config.paths.public.to_a.first
if config.compiled_asset_path && File.exist?(public_path)
config.static_asset_paths[config.compiled_asset_path] = public_path
end
end
protected
def find_root_with_flag(flag, default=nil)
root_path = self.class.called_from

View File

@@ -55,6 +55,10 @@ module Rails
def autoload_paths
@autoload_paths ||= paths.autoload_paths
end
def compiled_asset_path
asset_path % "" if asset_path
end
end
end
end

View File

@@ -5,6 +5,7 @@ module Rails
class Configuration
def initialize
@@options ||= {}
@@static_asset_paths = ActiveSupport::OrderedHash.new
end
# This allows you to modify the application's middlewares from Engines.
@@ -65,6 +66,13 @@ module Rails
super || @@options.key?(name.to_sym)
end
# static_asset_paths is a Hash containing asset_paths
# with associated public folders, like:
# { "/" => "/app/public", "/my_engine" => "app/engines/my_engine/public" }
def static_asset_paths
@@static_asset_paths
end
private
def method_missing(name, *args, &blk)

View File

@@ -287,6 +287,7 @@ module RailtiesTest
@plugin.write "public/bukkits.html", "/bukkits/bukkits.html"
app_file "public/app.html", "/app.html"
app_file "public/bukkits/file_from_app.html", "/bukkits/file_from_app.html"
boot_rails
@@ -297,6 +298,10 @@ module RailtiesTest
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")
env = Rack::MockRequest.env_for("/bukkits/file_from_app.html")
response = Rails.application.call(env)
assert_equal response[2].path, File.join(app_path, "public/bukkits/file_from_app.html")
end
test "shared engine should include application's helpers" do