-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
105 lines (85 loc) · 2.4 KB
/
app.rb
File metadata and controls
105 lines (85 loc) · 2.4 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
class App < Sinatra::Base
helpers Sinatra::Partials
configure do
set :root, File.dirname(__FILE__)
# Configure public directory
set :public, Proc.new { File.join(root, "public") }
# Configure HAML and SASS
set :haml, { :format => :html5 }
set :sass, { :style => :compressed } if ENV['RACK_ENV'] == 'production'
# session storage ? using cookies most likely
set :session, true
end
helpers do
def link_to text, url=nil
haml "%a{:href => '#{ url || text }'} #{ text }"
end
def link_to_unless_current text, url=nil
if url == request.path_info
text
else
link_to text, url
end
end
def img(name)
"<img src='images/#{name}' alt='#{name}' />"
end
def photo(name)
"<div class='big outer_border'><img src='photos/#{name}' alt='#{name}' class='inner_border' /></div>"
end
def small_photo(name)
"<div class='small outer_border'><img src='photos/#{name}' alt='#{name}' class='inner_border' /></div>"
end
end
# SASS stylesheet
get "/css/global.css" do
headers 'Content-Type' => 'text/css; charset=utf-8'
sass :"css/global"
end
# root level favicon.png
get '/favicon.png' do
send_file 'favicon.png', :disposition => 'inline'
end
get '/' do
haml :index, :layout => :'layouts/default'
end
get '/about' do
@title = "Fortunately Sweet : About Us"
haml :about, :layout => :'layouts/default'
end
get '/gallery' do
@title = "Fortunately Sweet : Cupcake Gallery"
haml :gallery, :layout => :'layouts/default'
end
get '/contact' do
@title = "Fortunately Sweet : Contact Us"
@email_sent = params[:email_sent]
@try_again = params[:try_again]
haml :contact, :layout => :'layouts/default'
end
post '/contact' do
begin
Notifier.feedback(
params[:email],
params[:message]
).deliver
rescue
return redirect '/contact?try_again=true'
end
redirect '/contact?email_sent=true'
end
# get '/form' do
# %{ <form action="/name" method="post">
# <input name="person" type="text">
# <input type="submit">
# </form> }
# end
#
# post '/name' do
# haml "Hello #{ params[:person] }", :layout => :'layouts/default'
# end
#
# get "/user/:id" do
# "You're looking for user with id #{ params[:id] }"
# end
end