bomberstudios / sinatra_wiki

An ultralight, ultraminimal wiki thing with Markdown

This URL has Read+Write access

sinatra_wiki / sinatra_wiki.rb
100644 54 lines (49 sloc) 1.021 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
%w(rubygems sinatra erb rdiscount thin yaml digest/sha1 haml).each do |lib|
  require lib
end
Dir["lib/**/*.rb"].each do |lib|
  require lib
end
 
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 = Dir["public/**/*.txt"]
  cache erb :home
end
get '/:slug' do
  @page = Page.new(params[:slug])
  if @page.is_new
    redirect "/#{@page.name}/edit"
  else
    @content = @page.html
    cache erb :page
  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 '/base.css' do
  cache sass :base
end