This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.rb
63 lines (51 loc) · 1.72 KB
/
application.rb
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
56
57
58
59
60
61
62
63
class MyApp < Sinatra::Base
$cache = 'heap:/'
use Rack::Cache,
:verbose => true,
:metastore => $cache,
:entitystore => $cache
configure do
set :root, Proc.new { File.expand_path(File.dirname(__FILE__)) }
set :app_file, Proc.new { File.join(root, __FILE__) }
set :views, Proc.new { File.join(root, 'app','views') }
set :public, Proc.new { File.join(root, 'public') }
disable :run
enable :sessions
Compass.configuration do |config|
config.output_style = :expanded
config.environment = Sinatra::Application.environment
config.project_path = Sinatra::Application.root
config.sass_path = Proc.new { File.join(Sinatra::Application.views, 'stylesheets') }
config.css_path = Proc.new { File.join(Sinatra::Application.public, 'stylesheets') }
config.images_path = Proc.new { File.join(Sinatra::Application.public, 'images') }
config.http_path = '/'
config.http_images_path = "/images"
config.http_stylesheets_path = "/stylesheets"
config.relative_assets = true
end
end
helpers Haml::More
before do
raw = @request.env["REMOTE_ADDR"]
raw.match(/^(\d+\.\d+\.\d+\.\d+),?/)
@remoteip ||= $1
cache_control :public, :max_age => 2 * 60
end
get '/' do
redirect '/index'
end
get '/:name' do
content_type :html
@title = "Your ip is #{@remoteip}"
haml :"#{params[:name]}", :layout => :'layouts/application'
end
get '/stylesheets/:name.css' do
content_type :css
sass :"stylesheets/#{params[:name]}",
:sass => Compass.sass_engine_options
end
get '/javascripts/:name.js' do
content_type :js
haml :"javascripts/#{params[:name]}"
end
end