public
Fork of sr/git-wiki
Description: A wiki engine that uses a Git repository as its data store.
Homepage: http://atonie.org/2008/02/git-wiki
Clone URL: git://github.com/al3x/git-wiki.git
Search Repo:
schacon (author)
Thu Mar 06 16:20:07 -0800 2008
commit  8e78701e35bdcbdc365f9569e2d52660900222e6
tree    f77fa5c569be513985eabb98ef597ccec9d1b7ac
parent  7bfdd2d3239f64f95426a8f44a9eb2df5c7725b1 parent  b0f4475857c54a55d030ea14f04137c96a771023
git-wiki / git-wiki.rb
100755 87 lines (69 sloc) 2.281 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
#!/usr/bin/env ruby
 
require 'environment'
 
require_gem_with_feedback 'sinatra'
 
layout { File.read('views/layout.erb') }
 
def show(template, title)
  @title = title
  erb(template)
end
 
def page_with_ext
  if params[:format] == "html"
    params[:page]
  else
    "#{params[:page]}.#{params[:format]}"
  end
end
 
def page_url
  "#{request.env["rack.url_scheme"]}://#{request.env["HTTP_HOST"]}#{request.env["REQUEST_PATH"]}"
end
 
get('/') { redirect '/' + HOMEPAGE }
get('/_style.css') { header 'Content-Type' => 'text/css'; File.read(File.join(File.dirname(__FILE__), 'css', 'style.css')) }
get('/_code.css') { header 'Content-Type' => 'text/css'; File.read(File.join(File.dirname(__FILE__), 'css', "#{UV_THEME}.css")) }
get('/_app.js') { header 'Content-Type' => 'application/x-javascript'; File.read(File.join(File.dirname(__FILE__), 'javascripts', "application.js")) }
 
get '/_list' do
  @pages = $repo.log.first.gtree.children.map { |name, blob| Page.new(name) } rescue []
  show(:list, 'Listing pages')
end
 
get '/:page' do
  @page_url = page_url
  @page = Page.new(page_with_ext)
  @page.tracked? ? show(:show, @page.name) : redirect('/e/' + @page.name)
end
 
get '/:page/append' do
  @page = Page.new(page_with_ext)
  @page.body = @page.raw_body + "\n\n" + params[:text]
  redirect '/' + @page.name
end
 
get '/e/:page' do
  @page = Page.new(page_with_ext)
  show :edit, "Editing #{@page.name}"
end
 
post '/e/:page' do
  @page = Page.new(page_with_ext)
  @page.body = params[:body]
  redirect '/' + @page.name
end
 
get '/h/:page' do
  @page = Page.new(page_with_ext)
  show :history, "History of #{@page.name}"
end
 
get '/h/:page/:rev' do
  @page = Page.new(page_with_ext, params[:rev])
  show :show, "#{@page.name} / version #{params[:rev]})"
end
 
# FIXME this repeats the above just to accomodate pages with
# file extensions. bad!
get '/h/:page.:format/:rev' do
  @page = Page.new(page_with_ext, params[:rev])
  show :show, "#{@page.name} / version #{params[:rev]})"
end
 
get '/d/:page/:rev' do
  @page = Page.new(page_with_ext)
  show :delta, "Diff of #{@page.name}"
end
 
# FIXME this repeats the above just to accomodate pages with
# file extensions. bad!
get '/d/:page.:format/:rev' do
  @page = Page.new(page_with_ext)
  show :delta, "Diff of #{@page.name}"
end