forked from patshaughnessy/code_buddy
/
app.rb
50 lines (40 loc) · 892 Bytes
/
app.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
module CodeBuddy
class App < Sinatra::Base
set :views, File.dirname(__FILE__) + '/views'
set :public, File.dirname(__FILE__) + '/public'
class << self
attr_reader :stack
def exception=(exception)
@stack = Stack.new(exception)
end
def stack_string=(stack_string)
@stack = Stack.new(stack_string)
end
end
get '/' do
display_stack(0)
end
get '/new' do
erb :form
end
post '/' do
self.class.stack_string = params[:stack]
redirect '/'
end
get '/stack' do
display_stack(0)
end
get '/:selected' do
display_stack(params[:selected].to_i)
end
def display_stack(selected_param)
@stack = self.class.stack
if @stack
@stack.selected = selected_param
erb :index
else
redirect '/new'
end
end
end
end