aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-09-26 11:37:42 -0500
committerJoshua Peek <josh@joshpeek.com>2009-09-26 11:37:42 -0500
commitef58194129a1dc0a96286c271b71455d37712b42 (patch)
tree8a40025c2bd3d773e80afbeea6478b6102fc8a57 /railties
parentdbb32115ef45dd58667e450125deba80d7016341 (diff)
downloadrails-ef58194129a1dc0a96286c271b71455d37712b42.tar.gz
rails-ef58194129a1dc0a96286c271b71455d37712b42.tar.bz2
rails-ef58194129a1dc0a96286c271b71455d37712b42.zip
Move Rails::Static into ActionDispatch
Diffstat (limited to 'railties')
-rw-r--r--railties/guides/source/rails_on_rack.textile11
-rw-r--r--railties/lib/rails/initializer.rb2
-rw-r--r--railties/lib/rails/rack/static.rb47
-rw-r--r--railties/test/fixtures/public/foo/bar.html1
-rw-r--r--railties/test/fixtures/public/foo/index.html1
-rw-r--r--railties/test/fixtures/public/index.html1
-rw-r--r--railties/test/rack_static_test.rb46
7 files changed, 8 insertions, 101 deletions
diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile
index 545aaa18e0..1ad45f1cca 100644
--- a/railties/guides/source/rails_on_rack.textile
+++ b/railties/guides/source/rails_on_rack.textile
@@ -40,11 +40,8 @@ Here's how +script/server+ creates an instance of +Rack::Builder+
app = Rack::Builder.new {
use Rails::Rack::LogTailer unless options[:detach]
use Rails::Rack::Debugger if options[:debugger]
-
- map "/" do
- use Rails::Rack::Static
- run ActionController::Dispatcher.new
- end
+ use ActionDispatch::Static
+ run ActionController::Dispatcher.new
}.to_app
</ruby>
@@ -52,7 +49,7 @@ Middlewares used in the code above are primarily useful only in the development
|_.Middleware|_.Purpose|
|+Rails::Rack::LogTailer+|Appends log file output to console|
-|+Rails::Rack::Static+|Serves static files inside +RAILS_ROOT/public+ directory|
+|+ActionDispatch::Static+|Serves static files inside +RAILS_ROOT/public+ directory|
|+Rails::Rack::Debugger+|Starts Debugger|
h4. +rackup+
@@ -64,7 +61,7 @@ To use +rackup+ instead of Rails' +script/server+, you can put the following ins
require "config/environment"
use Rails::Rack::LogTailer
-use Rails::Rack::Static
+use ActionDispatch::Static
run ActionController::Dispatcher.new
</ruby>
diff --git a/railties/lib/rails/initializer.rb b/railties/lib/rails/initializer.rb
index e6f42f643c..72d23f2642 100644
--- a/railties/lib/rails/initializer.rb
+++ b/railties/lib/rails/initializer.rb
@@ -272,7 +272,7 @@ module Rails
# Include middleware to serve up static assets
Initializer.default.add :initialize_static_server do
if configuration.frameworks.include?(:action_controller) && configuration.serve_static_assets
- configuration.middleware.insert(0, Rails::Rack::Static, Rails.public_path)
+ configuration.middleware.insert(0, ActionDispatch::Static, Rails.public_path)
end
end
diff --git a/railties/lib/rails/rack/static.rb b/railties/lib/rails/rack/static.rb
index 25b6cadbfc..d6b8face27 100644
--- a/railties/lib/rails/rack/static.rb
+++ b/railties/lib/rails/rack/static.rb
@@ -1,46 +1,5 @@
-require 'rack/utils'
+require 'action_dispatch'
-module Rails
- module Rack
- class Static
- FILE_METHODS = %w(GET HEAD).freeze
-
- def initialize(app, root)
- @app = app
- @file_server = ::Rack::File.new(root)
- end
-
- def call(env)
- path = env['PATH_INFO'].chomp('/')
- method = env['REQUEST_METHOD']
-
- if FILE_METHODS.include?(method)
- if file_exist?(path)
- return @file_server.call(env)
- else
- cached_path = directory_exist?(path) ? "#{path}/index" : path
- cached_path += ::ActionController::Base.page_cache_extension
-
- if file_exist?(cached_path)
- env['PATH_INFO'] = cached_path
- return @file_server.call(env)
- end
- end
- end
-
- @app.call(env)
- end
-
- private
- def file_exist?(path)
- full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
- File.file?(full_path) && File.readable?(full_path)
- end
-
- def directory_exist?(path)
- full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
- File.directory?(full_path) && File.readable?(full_path)
- end
- end
- end
+module Rails::Rack
+ Static = Deprecation::DeprecatedConstantProxy.new('Rails::Rack::Static', ActionDispatch::Static)
end
diff --git a/railties/test/fixtures/public/foo/bar.html b/railties/test/fixtures/public/foo/bar.html
deleted file mode 100644
index 9a35646205..0000000000
--- a/railties/test/fixtures/public/foo/bar.html
+++ /dev/null
@@ -1 +0,0 @@
-/foo/bar.html \ No newline at end of file
diff --git a/railties/test/fixtures/public/foo/index.html b/railties/test/fixtures/public/foo/index.html
deleted file mode 100644
index 497a2e898f..0000000000
--- a/railties/test/fixtures/public/foo/index.html
+++ /dev/null
@@ -1 +0,0 @@
-/foo/index.html \ No newline at end of file
diff --git a/railties/test/fixtures/public/index.html b/railties/test/fixtures/public/index.html
deleted file mode 100644
index 525950ba6b..0000000000
--- a/railties/test/fixtures/public/index.html
+++ /dev/null
@@ -1 +0,0 @@
-/index.html \ No newline at end of file
diff --git a/railties/test/rack_static_test.rb b/railties/test/rack_static_test.rb
deleted file mode 100644
index 695b011d03..0000000000
--- a/railties/test/rack_static_test.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-require 'abstract_unit'
-
-require 'action_controller'
-require 'rails/rack'
-
-class RackStaticTest < ActiveSupport::TestCase
- def setup
- FileUtils.cp_r "#{RAILS_ROOT}/fixtures/public", "#{RAILS_ROOT}/public"
- end
-
- def teardown
- FileUtils.rm_rf "#{RAILS_ROOT}/public"
- end
-
- DummyApp = lambda { |env|
- [200, {"Content-Type" => "text/plain"}, ["Hello, World!"]]
- }
- App = Rails::Rack::Static.new(DummyApp, "#{RAILS_ROOT}/public")
-
- test "serves dynamic content" do
- assert_equal "Hello, World!", get("/nofile")
- end
-
- test "serves static index at root" do
- assert_equal "/index.html", get("/index.html")
- assert_equal "/index.html", get("/index")
- assert_equal "/index.html", get("/")
- end
-
- test "serves static file in directory" do
- assert_equal "/foo/bar.html", get("/foo/bar.html")
- assert_equal "/foo/bar.html", get("/foo/bar/")
- assert_equal "/foo/bar.html", get("/foo/bar")
- end
-
- test "serves static index file in directory" do
- assert_equal "/foo/index.html", get("/foo/index.html")
- assert_equal "/foo/index.html", get("/foo/")
- assert_equal "/foo/index.html", get("/foo")
- end
-
- private
- def get(path)
- Rack::MockRequest.new(App).request("GET", path).body
- end
-end