6 require 'syntax/convertors/html'
10 # this is meant to be a git-less web head to your git repo
12 # install dependencies
13 # sudo gem install camping-omnibus --source http://code.whytheluckystiff.net
15 # author : scott chacon
16 # thanks to dr. nic for his syntax code highlighting deal
18 # /usr/local/lib/ruby/gems/1.8/gems/camping-1.5.180/examples/
23 class Repository < Base; end
25 class CreateGitWeb < V 0.1
27 create_table :gitweb_repositories, :force => true do |t|
28 t.column :name, :string
29 t.column :path, :string
30 t.column :bare, :boolean
36 module GitWeb::Controllers
39 @repos = Repository.find :all
44 class Stylesheet < R '/css/highlight.css'
46 @headers['Content-Type'] = 'text/css'
47 ending = File.read(__FILE__).gsub(/.*__END__/m, '')
48 ending.gsub(/__END__.*/m, '')
52 class JsHighlight < R '/js/highlight.js'
54 @headers['Content-Type'] = 'text/css'
55 File.read(__FILE__).gsub(/.*__JS__/m, '')
59 class View < R '/view/(\d+)'
61 @repo = Repository.find repo_id
62 @git = Git.bare(@repo.path)
67 class Fetch < R '/git/(\d+)'
69 @repo = Repository.find repo_id
70 @git = Git.bare(@repo.path)
76 @repo = Repository.new
80 if Git.bare(input.repository_path)
81 repo = Repository.create :name => input.repo_name, :path => input.repo_path, :bare => input.repo_bare
89 class Commit < R '/commit/(\d+)/(\w+)'
91 @repo = Repository.find repo_id
92 @git = Git.bare(@repo.path)
93 @commit = @git.gcommit(sha)
98 class Tree < R '/tree/(\d+)/(\w+)'
100 @repo = Repository.find repo_id
101 @git = Git.bare(@repo.path)
102 @tree = @git.gtree(sha)
107 class Blob < R '/blob/(\d+)/(.*?)/(\w+)'
108 def get repo_id, file, sha
109 @repo = Repository.find repo_id
110 @git = Git.bare(@repo.path)
111 @blob = @git.gblob(sha)
117 class BlobRaw < R '/blob/(\d+)/(\w+)'
119 @repo = Repository.find repo_id
120 @git = Git.bare(@repo.path)
121 @blob = @git.gblob(sha)
126 class Archive < R '/archive/(\d+)/(\w+)'
128 @repo = Repository.find repo_id
129 @git = Git.bare(@repo.path)
131 file = @git.gtree(sha).archive
132 @headers['Content-Type'] = 'application/zip'
133 @headers["Content-Disposition"] = "attachment; filename=archive.zip"
138 class Diff < R '/diff/(\d+)/(\w+)/(\w+)'
139 def get repo_id, tree1, tree2
140 @repo = Repository.find repo_id
141 @git = Git.bare(@repo.path)
144 @diff = @git.diff(tree1, tree2)
149 class Patch < R '/patch/(\d+)/(\w+)/(\w+)'
150 def get repo_id, tree1, tree2
151 @repo = Repository.find repo_id
152 @git = Git.bare(@repo.path)
153 @diff = @git.diff(tree1, tree2).patch
164 #link :href=>R(Stylesheet), :rel=>'stylesheet', :type=>'text/css'
165 #script :type => "text/javascript", :language => "JavaScript", :src => R(JsHighlight)
167 style <<-END, :type => 'text/css'
168 body { color: #333; }
169 h1 { background: #cce; padding: 10px; margin: 3px; }
170 h3 { background: #aea; padding: 5px; margin: 3px; }
171 .options { float: right; margin: 10px; }
173 .odd { background: #eee; }
174 .tag { margin: 5px; padding: 1px 3px; border: 1px solid #8a8; background: #afa;}
175 .indent { padding: 0px 15px;}
176 .tip { border-top: 1px solid #aaa; color: #666; padding: 10px; }
189 @git.tags.each { |tag| @tags[tag.sha] ||= []; @tags[tag.sha] << tag.name }
191 url = 'http:' + URL(Fetch, @repo.id).to_s
195 tr { td 'owner: '; td @git.config('user.name') }
196 tr { td 'email: '; td @git.config('user.email') }
197 tr { td 'url: '; td { a url, :href => url } }
202 @git.log.each do |log|
204 td log.date.strftime("%Y-%m-%d")
206 td { em log.author.name }
208 span.message log.message[0, 60]
209 @tags[log.sha].each do |t|
212 end if @tags[log.sha]
214 td { a 'commit', :href => R(Commit, @repo, log.sha) }
215 td { a 'commit-diff', :href => R(Diff, @repo, log.sha, log.parent.sha) }
216 td { a 'tree', :href => R(Tree, @repo, log.gtree.sha) }
217 td { a 'archive', :href => R(Archive, @repo, log.gtree.sha) }
223 @git.branches.each do |branch|
224 li { a branch.full, :href => R(Commit, @repo, branch.gcommit.sha) }
228 @git.tags.each do |tag|
229 li { a tag.name, :href => R(Commit, @repo, tag.sha) }
235 a.options 'repo', :href => R(View, @repo)
239 tr { td 'author: '; td @commit.author.name + ' <' + @commit.author.email + '>'}
240 tr { td ''; td { code @commit.author.date } }
241 tr { td 'committer: '; td @commit.committer.name + ' <' + @commit.committer.email + '>'}
242 tr { td ''; td { code @commit.committer.date } }
243 tr { td 'commit sha: '; td { code @commit.sha } }
247 code { a @commit.gtree.sha, :href => R(Tree, @repo, @commit.gtree.sha) }
249 a 'archive', :href => R(Archive, @repo, @commit.gtree.sha)
255 @commit.parents.each do |p|
256 code { a p.sha, :href => R(Commit, @repo, p.sha) }
258 a 'diff', :href => R(DiffTwo, @repo, p.sha, @commit.sha)
260 a 'archive', :href => R(Archive, @repo, p.gtree.sha)
271 a.options 'repo', :href => R(View, @repo)
272 h3 'tree : ' + @tree.sha
273 p { a 'archive tree', :href => R(Archive, @repo, @tree.sha) };
275 @tree.children.each do |file, node|
276 tr :class => cycle('odd','even') do
277 td { code node.sha[0, 8] }
280 if node.type == 'tree'
281 td { a node.type, :href => R(Tree, @repo, node.sha) }
282 td { a 'archive', :href => R(Archive, @repo, node.sha) }
284 td { a node.type, :href => R(Blob, @repo, file, node.sha) }
285 td { a 'raw', :href => R(BlobRaw, @repo, node.sha) }
293 link :rel => "stylesheet", :type => "text/css",
294 :href => "http://drnicwilliams.com/external/CodeHighlighter/styles.css"
295 script :src => "http://drnicwilliams.com/external/CodeHighlighter/clean_tumblr_pre.js"
297 ext = File.extname(@file).gsub('.', '')
298 ext = 'ruby' if ext == 'rb'
300 a.options 'repo', :href => R(View, @repo)
301 h3 'blob : ' + @blob.sha
303 pre { code @blob.contents, :class => ext }
307 a.options 'repo', :href => R(View, @repo)
310 p { a 'download patch file', :href => R(Patch, @repo, @tree1, @tree2) }
313 a @tree1, :href => R(Tree, @repo, @tree1)
315 a @tree2, :href => R(Tree, @repo, @tree2)
321 convertor = Syntax::Convertors::HTML.for_syntax "diff"
322 self << convertor.convert( file.patch )
324 div.indent { pre file.patch }
325 div.tip 'tip: if you run "gem install syntax", this will be highlighted'
333 (@value == v1) ? @value = v2 : @value = v1
342 form(:method => 'post') do
343 label 'Path', :for => 'repo_path'; br
344 input :name => 'repo_path', :type => 'text', :value => repo.path; br
346 label 'Name', :for => 'repo_name'; br
347 input :name => 'repo_name', :type => 'text', :value => repo.name; br
349 label 'Bare', :for => 'repo_bare'; br
350 input :type => 'checkbox', :name => 'repo_bare', :value => repo.bare; br
352 input :type => 'hidden', :name => 'repo_id', :value => repo.id
353 input :type => 'submit'
358 @repos.each do | repo |
360 a repo.path, :href => R(View, repo.id)
364 a 'add new repo', :href => R(Add)
369 GitWeb::Models.create_schema