Permalink
Browse files

Get rid of static_paths method and instead configure paths for Action…

…Dispatch::Static in initializers
  • Loading branch information...
1 parent d812677 commit 8284fd38551c00c30cf89fa22d1afd503a08c516 @drogus drogus committed Aug 4, 2010
@@ -145,25 +145,9 @@ def config
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
@@ -37,6 +37,10 @@ def asset_host=(value)
super(value)
end
+ def compiled_asset_path
+ "/"
+ end
+
def encoding=(value)
@encoding = value
if "ruby".encoding_aware?
@@ -428,6 +428,13 @@ def config
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
@@ -55,6 +55,10 @@ def autoload_once_paths
def autoload_paths
@autoload_paths ||= paths.autoload_paths
end
+
+ def compiled_asset_path
+ asset_path % "" if asset_path
+ end
end
end
end
@@ -5,6 +5,7 @@ class Railtie
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 @@ def respond_to?(name)
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)
@@ -287,6 +287,7 @@ class Engine < ::Rails::Engine
@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 @@ class Engine < ::Rails::Engine
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

0 comments on commit 8284fd3

Please sign in to comment.