Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v0.6.4
Fetching contributors…

Cannot retrieve contributors at this time

48 lines (40 sloc) 1.121 kb
require "rack/offline"
module Rails
class Offline < ::Rack::Offline
def self.call(env)
@app ||= new
@app.call(env)
end
def initialize(options = {}, app = Rails.application, &block)
config = app.config
root = config.paths['public'].first
block = cache_block(Pathname.new(root)) unless block_given?
opts = {
:cache => config.cache_classes,
:root => root,
:logger => Rails.logger
}.merge(options)
super(opts, &block)
end
private
def cache_block(root)
Proc.new do
if Rails.version >= "3.1" && Rails.configuration.assets.enabled
files = Dir[
"#{root}/**/*.html",
"#{root}/assets/**/*.{js,css,jpg,png,gif}"]
else
files = Dir[
"#{root}/**/*.html",
"#{root}/stylesheets/**/*.css",
"#{root}/javascripts/**/*.js",
"#{root}/images/**/*.*"]
end
files.each do |file|
cache Pathname.new(file).relative_path_from(root)
end
network "*"
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.