forked from bomberstudios/sinatra_wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sinatra_wiki.rb
54 lines (49 loc) · 968 Bytes
/
sinatra_wiki.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
require 'requires'
configure do
@config = YAML::load(File.read('config.yml')).to_hash.each do |k,v|
set k, v
end
end
configure :development do
%x(rake expire_cache)
set :cache_enabled, false
end
before do
content_type 'text/html', :charset => 'utf-8'
@page = Page.new("home") # Default page
end
get '/' do
@pages = Page.pages
cache erb(:home)
end
get '/:slug' do
@page = Page.new(params[:slug])
if @page.exists?
@content = @page.html
cache erb(:page)
else
redirect "/#{@page.name}/edit"
end
end
get '/:slug/edit' do
auth
@page = Page.new(params[:slug])
erb :edit
end
post '/:slug/edit' do
auth
nice_title = Slugalizer.slugalize(params[:title])
@page = Page.new(nice_title)
@page.content = params[:body]
expire_cache "/"
expire_cache "/#{nice_title}"
redirect "/#{nice_title}"
end
get '/:slug/destroy' do
auth
Page.destroy(params[:slug])
redirect "/"
end
get '/base.css' do
cache sass(:base)
end