提交 092b148b 编写于 作者: P Piotr Sarnacki

Engine can now serve files with ActionDispatch::Static

上级 c989d1a8
......@@ -11,7 +11,7 @@ class Configuration < ::Rails::Engine::Configuration
: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 @@ def railties
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 @@ class Engine
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 @@ def method_missing(name, *args, &blk)
end
end
end
end
\ No newline at end of file
end
......@@ -127,5 +127,31 @@ class Engine < ::Rails::Engine
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册