al3x / git-wiki forked from sr/git-wiki

A wiki engine that uses a Git repository as its data store.

This URL has Read+Write access

schacon (author)
Sun Apr 20 18:22:53 -0700 2008
commit  d294bebf8a4b9364727d472560fb8cf7bf553c47
tree    32713e34ee4584140b8290c95c3ea20ffa29bf3e
parent  22cf4df0a579c7591f5de47c1c7de26ec865744b
git-wiki / git-wiki.rb
cd4545f4 » Alex Payne 2008-02-19 provide feedback amount mis... 1 #!/usr/bin/env ruby
2
22cf4df0 » schacon 2008-04-20 added file upload functiona... 3 require 'fileutils'
26b9e050 » al3x 2008-03-01 move things out to external... 4 require 'environment'
695dd368 » al3x 2008-03-20 add sinatra as a git submod... 5 require 'sinatra/lib/sinatra'
3ff58573 » schacon 2008-03-07 added branching 6
06f53f5f » al3x 2008-03-14 edit-in-place. thanks, jQu... 7 get('/') { redirect "/#{HOMEPAGE}" }
3bdddd51 » Simon Rozet 2008-01-29 Initial import 8
046dceb6 » al3x 2008-03-15 better looking search box, ... 9 # page paths
68eeb527 » Simon Rozet 2008-01-31 I can has list of pages? 10
3bdddd51 » Simon Rozet 2008-01-29 Initial import 11 get '/:page' do
14d211cf » al3x 2008-03-14 remove dependency on ultrav... 12 @page = Page.new(params[:page])
3bdefe77 » anotherjesse 2008-02-21 move views to external erb ... 13 @page.tracked? ? show(:show, @page.name) : redirect('/e/' + @page.name)
3bdddd51 » Simon Rozet 2008-01-29 Initial import 14 end
15
06f53f5f » al3x 2008-03-14 edit-in-place. thanks, jQu... 16 get '/:page/raw' do
17 @page = Page.new(params[:page])
18 @page.raw_body
19 end
20
f37914b8 » Alex Payne 2008-02-26 append bookmarklet 21 get '/:page/append' do
14d211cf » al3x 2008-03-14 remove dependency on ultrav... 22 @page = Page.new(params[:page])
f37914b8 » Alex Payne 2008-02-26 append bookmarklet 23 @page.body = @page.raw_body + "\n\n" + params[:text]
24 redirect '/' + @page.name
25 end
26
3bdddd51 » Simon Rozet 2008-01-29 Initial import 27 get '/e/:page' do
14d211cf » al3x 2008-03-14 remove dependency on ultrav... 28 @page = Page.new(params[:page])
3bdefe77 » anotherjesse 2008-02-21 move views to external erb ... 29 show :edit, "Editing #{@page.name}"
3bdddd51 » Simon Rozet 2008-01-29 Initial import 30 end
31
32 post '/e/:page' do
14d211cf » al3x 2008-03-14 remove dependency on ultrav... 33 @page = Page.new(params[:page])
c97c066c » schacon 2008-03-08 you can now add commit mess... 34 @page.update(params[:body], params[:message])
3bdddd51 » Simon Rozet 2008-01-29 Initial import 35 redirect '/' + @page.name
36 end
37
06f53f5f » al3x 2008-03-14 edit-in-place. thanks, jQu... 38 post '/eip/:page' do
14d211cf » al3x 2008-03-14 remove dependency on ultrav... 39 @page = Page.new(params[:page])
06f53f5f » al3x 2008-03-14 edit-in-place. thanks, jQu... 40 @page.update(params[:body])
41 @page.body
42 end
43
0426baab » anotherjesse 2008-02-21 make /h/page show history o... 44 get '/h/:page' do
14d211cf » al3x 2008-03-14 remove dependency on ultrav... 45 @page = Page.new(params[:page])
3bdefe77 » anotherjesse 2008-02-21 move views to external erb ... 46 show :history, "History of #{@page.name}"
0426baab » anotherjesse 2008-02-21 make /h/page show history o... 47 end
48
14d211cf » al3x 2008-03-14 remove dependency on ultrav... 49 get '/h/:page/:rev' do
50 @page = Page.new(params[:page], params[:rev])
51 show :show, "#{@page.name} (version #{params[:rev]})"
f3f2adcb » Simon Rozet 2008-02-15 Lots of layout modifications 52 end
6d64782e » Alex Payne 2008-02-24 fix some routes to handle f... 53
14d211cf » al3x 2008-03-14 remove dependency on ultrav... 54 get '/d/:page/:rev' do
55 @page = Page.new(params[:page])
56 show :delta, "Diff of #{@page.name}"
6d64782e » Alex Payne 2008-02-24 fix some routes to handle f... 57 end
08c0cd93 » schacon 2008-03-06 added tarball download 58
046dceb6 » al3x 2008-03-15 better looking search box, ... 59 # application paths (/a/ namespace)
60
61 get '/a/list' do
d294bebf » schacon 2008-04-20 cleaned _ directoried from ... 62 pages = $repo.log.first.gtree.children
63 @pages = pages.select { |f,bl| f[0,1] != '_'}.sort.map { |name, blob| Page.new(name) } rescue []
046dceb6 » al3x 2008-03-15 better looking search box, ... 64 show(:list, 'Listing pages')
65 end
66
fb02f55f » schacon 2008-03-08 added patch file download 67 get '/a/patch/:page/:rev' do
14d211cf » al3x 2008-03-14 remove dependency on ultrav... 68 @page = Page.new(params[:page])
fb02f55f » schacon 2008-03-08 added patch file download 69 header 'Content-Type' => 'text/x-diff'
70 header 'Content-Disposition' => 'filename=patch.diff'
71 @page.delta(params[:rev])
72 end
73
08c0cd93 » schacon 2008-03-06 added tarball download 74 get '/a/tarball' do
75 header 'Content-Type' => 'application/x-gzip'
76 header 'Content-Disposition' => 'filename=archive.tgz'
77 archive = $repo.archive('HEAD', nil, :format => 'tgz', :prefix => 'wiki/')
78 File.open(archive).read
3ff58573 » schacon 2008-03-07 added branching 79 end
80
81 get '/a/branches' do
82 @branches = $repo.branches
83 show :branches, "Branches List"
84 end
85
86 get '/a/branch/:branch' do
87 $repo.checkout(params[:branch])
88 redirect '/' + HOMEPAGE
89 end
90
0876ca32 » schacon 2008-03-07 added branch history and ba... 91 get '/a/history' do
92 @history = $repo.log
93 show :branch_history, "Branch History"
94 end
95
96 get '/a/revert_branch/:sha' do
97 $repo.with_temp_index do
98 $repo.read_tree params[:sha]
99 $repo.checkout_index
100 $repo.commit('reverted branch')
101 end
102 redirect '/a/history'
103 end
104
07441fab » schacon 2008-03-07 can merge branches now - ma... 105 get '/a/merge_branch/:branch' do
106 $repo.merge(params[:branch])
c97c066c » schacon 2008-03-08 you can now add commit mess... 107 redirect '/' + HOMEPAGE
07441fab » schacon 2008-03-07 can merge branches now - ma... 108 end
109
3ff58573 » schacon 2008-03-07 added branching 110 get '/a/delete_branch/:branch' do
111 $repo.branch(params[:branch]).delete
112 redirect '/a/branches'
113 end
114
115 post '/a/new_branch' do
116 $repo.branch(params[:branch]).create
117 $repo.checkout(params[:branch])
118 if params[:type] == 'blank'
119 # clear out the branch
120 $repo.chdir do
121 Dir.glob("*").each do |f|
122 File.unlink(f)
123 $repo.remove(f)
124 end
125 touchfile
126 $repo.commit('clean branch start')
127 end
128 end
129 redirect '/a/branches'
130 end
e7718c56 » schacon 2008-03-08 added remote branch support... 131
132 post '/a/new_remote' do
133 $repo.add_remote(params[:branch_name], params[:branch_url])
134 $repo.fetch(params[:branch_name])
135 redirect '/a/branches'
3fe21594 » schacon 2008-03-08 added search through git-grep 136 end
137
138 get '/a/search' do
139 @search = params[:search]
140 @grep = $repo.grep(@search)
141 show :search, 'Search Results'
c0faf90e » al3x 2008-03-14 massive reorganization 142 end
143
22cf4df0 » schacon 2008-04-20 added file upload functiona... 144 # file upload attachments
145
146 get '/a/file/upload/:page' do
147 @page = Page.new(params[:page])
148 show :attach, 'Attach File for ' + @page.name
149 end
150
151 post '/a/file/upload/:page' do
152 @page = Page.new(params[:page])
153 @page.save_file(params[:file], params[:name])
154 redirect '/e/' + @page.name
155 end
156
157 get '/a/file/delete/:page/:file.:ext' do
158 @page = Page.new(params[:page])
159 @page.delete_file(params[:file] + '.' + params[:ext])
160 redirect '/e/' + @page.name
161 end
162
163 get '/_attachment/:page/:file.:ext' do
164 @page = Page.new(params[:page])
165 send_file(File.join(@page.attach_dir, params[:file] + '.' + params[:ext]))
166 end
167
046dceb6 » al3x 2008-03-15 better looking search box, ... 168 # support methods
169
95237532 » al3x 2008-03-15 prettier search results page 170 def page_url(page)
171 "#{request.env["rack.url_scheme"]}://#{request.env["HTTP_HOST"]}/#{page}"
c0faf90e » al3x 2008-03-14 massive reorganization 172 end
173
174 private
175
176 def show(template, title)
177 @title = title
178 erb(template)
179 end
180
181 def touchfile
182 # adds meta file to repo so we have somthing to commit initially
183 $repo.chdir do
184 f = File.new(".meta", "w+")
185 f.puts($repo.current_branch)
186 f.close
187 $repo.add('.meta')
188 end
22cf4df0 » schacon 2008-04-20 added file upload functiona... 189 end