mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Engine can now serve files with ActionDispatch::Static
This commit is contained in:
@@ -11,7 +11,7 @@ module Rails
|
||||
:encoding, :consider_all_requests_local, :dependency_loading,
|
||||
:filter_parameters, :log_level, :logger,
|
||||
:preload_frameworks, :reload_plugins,
|
||||
:secret_token, :serve_static_assets, :session_options,
|
||||
:secret_token, :session_options,
|
||||
:time_zone, :whiny_nils
|
||||
|
||||
def initialize(*)
|
||||
|
||||
@@ -152,13 +152,22 @@ module Rails
|
||||
end
|
||||
|
||||
def app
|
||||
@app ||= config.middleware.build(endpoint)
|
||||
@app ||= begin
|
||||
config.middleware = config.middleware.merge_into(default_middleware_stack)
|
||||
config.middleware.build(endpoint)
|
||||
end
|
||||
end
|
||||
|
||||
def endpoint
|
||||
self.class.endpoint || routes
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
def call(env)
|
||||
app.call(env)
|
||||
end
|
||||
|
||||
@@ -5,12 +5,13 @@ module Rails
|
||||
class Configuration < ::Rails::Railtie::Configuration
|
||||
attr_reader :root
|
||||
attr_writer :eager_load_paths, :autoload_once_paths, :autoload_paths
|
||||
attr_accessor :middleware, :plugins
|
||||
attr_accessor :middleware, :plugins, :serve_static_assets
|
||||
|
||||
def initialize(root=nil)
|
||||
super()
|
||||
@root = root
|
||||
@middleware = ActionDispatch::MiddlewareStack.new
|
||||
@serve_static_assets = true
|
||||
@middleware = Rails::Configuration::MiddlewareStackProxy.new
|
||||
end
|
||||
|
||||
def paths
|
||||
|
||||
@@ -78,4 +78,4 @@ module Rails
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -127,5 +127,31 @@ module RailtiesTest
|
||||
|
||||
assert Bukkits::Engine.config.yaffle_loaded
|
||||
end
|
||||
|
||||
test "engine can serve files" do
|
||||
@plugin.write "lib/bukkits.rb", <<-RUBY
|
||||
class Bukkits
|
||||
class Engine < ::Rails::Engine
|
||||
paths.public = "#{File.join(@plugin.path, "lib/bukkits/public")}"
|
||||
config.serve_static_assets = true
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
@plugin.write "lib/bukkits/public/omg.txt", <<-RUBY
|
||||
OMG
|
||||
RUBY
|
||||
|
||||
boot_rails
|
||||
|
||||
Rails::Application.routes.draw do |map|
|
||||
mount(Bukkits::Engine => "/bukkits")
|
||||
end
|
||||
|
||||
env = Rack::MockRequest.env_for("/bukkits/omg.txt")
|
||||
response = Rails::Application.call(env)
|
||||
|
||||
assert_equal response[2].path, File.join(@plugin.path, "lib/bukkits/public/omg.txt")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user