/
quirky.rb
55 lines (42 loc) · 954 Bytes
/
quirky.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
QREPOSITORY_PATH = FileUtils.pwd + "/system"
%w{boot sinatra}.each {|lib| require lib}
#TODO Validation. Security/authentication. Branching site. Git remote adding and removing.
# => Previewing. Better error handling. Sitemap generation. Admin section.
before do
end
error QuirkyNotFoundException do
throw :halt, [404, "File not found"]
end
helpers do
def partial(partial, options={})
haml partial, options.merge!(:layout => false)
end
def redirect_to(page)
redirect "/#{page.to_s}.html"
end
end
get "/" do
redirect_to :index
end
get "/:name.html" do
@page = Page.find(params[:name])
haml :page
end
get "/new" do
@page = Page.new
haml :new
end
post "/" do
redirect_to Page.save(params)
end
get "/update/:name.html" do
@page = Page.find(params[:name])
haml :update
end
put "/:name.html" do
redirect_to Page.save(params)
end
delete "/:name.html" do
Page.destroy(params[:name])
redirect "/"
end