Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 50 lines (39 sloc) 0.929 kB
0209434 Implement static key => value shortcuts.
Jimmy Kittiyachavalit authored
1 module Detour
2 class Application < Sinatra::Base
3 def self.public_dir
4 "public"
5 end
6
7 set :static, true
8 set :public, public_dir
9
10 get '*' do
11 File.read(File.join(Application.public_dir, 'index.html'))
12 end
13 end
14
15 class Offline < ::Rack::Offline
16 def initialize(app=nil, &block)
17 root = Application.public_dir
18
19 options = {
20 :cache => true,
21 :root => root
22 }
23
24 block = cache_block(Pathname.new(root)) unless block_given?
25
26 super(options, &block)
27 end
28
29 private
30
31 def cache_block(root)
32 lambda do
33 files = Dir[
34 "#{root}/**/*.html",
35 "#{root}/javascripts/**/*.js",
36 ]
37
38 files.each do |file|
39 cache(Pathname.new(file).relative_path_from(root))
40 end
41
42 fallback(
43 "/" => "/index.html"
44 )
45 network("*")
46 end
47 end
48 end
49 end
Something went wrong with that request. Please try again.