-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ru
56 lines (43 loc) · 1.36 KB
/
config.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# I use this for local testing. Hopefully I don't check this in.
# $LOAD_PATH << File.join( File.expand_path(File.dirname(__FILE__)), '../tiny_site/lib')
require 'tiny_site'
require 'tiny_site/version'
require 'rack/rewrite'
module Rack
class Runtime
def initialize(app)
@app = app
end
def call(env)
started_at = Time.now
status, headers, body = @app.call(env)
duration = Time.now - started_at
headers['X-Runtime'] = ("%0.6f" % duration)
[status, headers, body]
end
end
end
use Rack::Runtime
use Rack::CommonLogger
use Rack::ContentLength
use Rack::Rewrite do
rewrite '/robots.txt', '/static/robots.txt'
rewrite '/favicon.ico', '/static/favicon.ico'
end
use Rack::Static, :urls => ['/stylesheets','/javascript','/static'], :root => 'public'
class TinySite::View
def link_to(url, name=url, opts={})
opts, name = name, url if name.is_a? Hash
o = opts.map{|k,v| %Q{ #{k}="#{v}"} }.join
%Q{<a href="#{url}"#{o}>#{name}</a>}
end
def navigation
lis = global[:navigation].map do |url,name|
opts = {}
opts.update({:class => 'active'}) if request_path==url
%Q{ <li>#{link_to url, name, opts}</li>\n}
end
%Q{<ul>\n#{lis.join}</ul>\n}
end
end
run TinySite.new :file_path => 'https://dl.dropbox.com/s/d55gpsn2e4196uh', :file_path_postfix => '?dl=1'