class LocalStatic

Test custom static asset overrides in development mode. Looks for stylesheets, JavaScripts, etc. in local/public. Handled by web server in production.

Constants

FILE_METHODS

Public Class Methods

new(app) click to toggle source
# File app/rack/local_static.rb, line 8
def initialize(app)
  @app = app
  @local_file_server = ::Rack::File.new(::File.join(::Rails.root.to_s, "local", "public"))
end

Public Instance Methods

call(env) click to toggle source
# File app/rack/local_static.rb, line 13
def call(env)
  path        = env['PATH_INFO'].chomp('/')
  method      = env['REQUEST_METHOD']
  cached_path = (path.empty? ? 'index' : path) + ::ActionController::Base.page_cache_extension

  if FILE_METHODS.include?(method)
    if local_file_exist?(path)
      return @local_file_server.call(env)
    elsif local_file_exist?(cached_path)
      env['PATH_INFO'] = cached_path
      return @local_file_server.call(env)
    end
  end

  @app.call(env)
end