summaryrefslogtreecommitdiffstats
path: root/camping
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.(none)>2007-11-18 12:48:39 -0800
committerscott Chacon <schacon@agadorsparticus.(none)>2007-11-18 12:48:39 -0800
commitbaf3d420b48cc4e665cd54dde8c58d3cc66bd4a6 (patch)
treeb63585f59758d0b74d33a71099f4bd253e2e5f72 /camping
parent05afcafb2d40b3b0ee19f394a8b6ca4ebef7c9ce (diff)
downloadthird_party-ruby-git-baf3d420b48cc4e665cd54dde8c58d3cc66bd4a6.tar.gz
third_party-ruby-git-baf3d420b48cc4e665cd54dde8c58d3cc66bd4a6.tar.xz
third_party-ruby-git-baf3d420b48cc4e665cd54dde8c58d3cc66bd4a6.zip
just about done with the camping interface
Diffstat (limited to 'camping')
-rw-r--r--camping/gitweb.rb192
1 files changed, 176 insertions, 16 deletions
diff --git a/camping/gitweb.rb b/camping/gitweb.rb
index 433f582..95d4338 100644
--- a/camping/gitweb.rb
+++ b/camping/gitweb.rb
@@ -8,6 +8,8 @@ require 'git'
# sudo gem install camping-omnibus --source http://code.whytheluckystiff.net
#
# author : scott chacon
+# thanks to dr. nic for his syntax code highlighting deal
+#
# /usr/local/lib/ruby/gems/1.8/gems/camping-1.5.180/examples/
Camping.goes :GitWeb
@@ -72,17 +74,80 @@ module GitWeb::Controllers
render :commit
end
end
- class Diff < R '/diff/(\d+)/(\w+)'
- end
+
class Tree < R '/tree/(\d+)/(\w+)'
+ def get repo_id, sha
+ @repo = Repository.find repo_id
+ @git = Git.bare(@repo.path)
+ @tree = @git.gtree(sha)
+ render :tree
+ end
+ end
+
+ class Blob < R '/blob/(\d+)/(.*?)/(\w+)'
+ def get repo_id, file, sha
+ @repo = Repository.find repo_id
+ @git = Git.bare(@repo.path)
+ @blob = @git.gblob(sha)
+ @file = file
+ render :blob
+ end
+ end
+
+ class BlobRaw < R '/blob/(\d+)/(\w+)'
+ def get repo_id, sha
+ @repo = Repository.find repo_id
+ @git = Git.bare(@repo.path)
+ @blob = @git.gblob(sha)
+ @blob.contents
+ end
+ end
+
+ class Archive < R '/archive/(\d+)/(\w+)'
+ def get repo_id, sha
+ @repo = Repository.find repo_id
+ @git = Git.bare(@repo.path)
+
+ file = @git.gtree(sha).archive
+ @headers['Content-Type'] = 'application/zip'
+ @headers["Content-Disposition"] = "attachment; filename=archive.zip"
+ File.new(file).read
+ end
+ end
+
+ class Diff < R '/diff/(\d+)/(\w+)/(\w+)'
+ def get repo_id, tree1, tree2
+ @repo = Repository.find repo_id
+ @git = Git.bare(@repo.path)
+ @tree1 = tree1
+ @tree2 = tree2
+ @diff = @git.diff(tree1, tree2)
+ render :diff
+ end
end
- class Archive < R '/archive/(\d+)/(\W+)'
+
+ class Patch < R '/patch/(\d+)/(\w+)/(\w+)'
+ def get repo_id, tree1, tree2
+ @repo = Repository.find repo_id
+ @git = Git.bare(@repo.path)
+ @diff = @git.diff(tree1, tree2).patch
+ end
end
+
end
module GitWeb::Views
def layout
html do
+ style <<-END, :type => 'text/css'
+ body { color: #333; }
+ h1 { background: #cce; padding: 10px; margin: 3px; }
+ h3 { background: #aea; padding: 5px; margin: 3px; }
+ .options { float: right; margin: 10px; }
+ p { padding: 5px; }
+ .odd { background: #eee; }
+ .tag { margin: 5px; padding: 1px 3px; border: 1px solid #8a8; background: #afa;}
+ END
body do
self << yield
end
@@ -93,6 +158,9 @@ module GitWeb::Views
h1 @repo.name
h2 @repo.path
+ @tags = {}
+ @git.tags.each { |tag| @tags[tag.sha] ||= []; @tags[tag.sha] << tag.name }
+
url = 'http:' + URL(Fetch, @repo.id).to_s
h3 'info'
@@ -109,31 +177,123 @@ module GitWeb::Views
td log.date.strftime("%Y-%m-%d")
td log.sha[0, 8]
td { em log.author.name }
- td log.message[0, 60]
+ td do
+ span.message log.message[0, 60]
+ @tags[log.sha].each do |t|
+ span.space ' '
+ span.tag { code t }
+ end if @tags[log.sha]
+ end
td { a 'commit', :href => R(Commit, @repo, log.sha) }
- td { a 'diff', :href => R(Diff, @repo, log.sha) }
- td { a 'tree', :href => R(Tree, @repo, log.sha) }
- td { a 'archive', :href => R(Archive, @repo, log.sha) }
+ td { a 'commit-diff', :href => R(Diff, @repo, log.sha, log.parent.sha) }
+ td { a 'tree', :href => R(Tree, @repo, log.gtree.sha) }
+ td { a 'archive', :href => R(Archive, @repo, log.gtree.sha) }
end
end
end
- h3 'heads'
+ h3 'branches'
@git.branches.each do |branch|
- li branch.full
+ li { a branch.full, :href => R(Commit, @repo, branch.gcommit.sha) }
+ end
+
+ h3 'tags'
+ @git.tags.each do |tag|
+ li { a tag.name, :href => R(Commit, @repo, tag.sha) }
end
+
end
def commit
+ a.options 'repo', :href => R(View, @repo)
h1 @commit.name
- h2 @commit.sha
+ h3 'info'
+ table.info do
+ tr { td 'author: '; td @commit.author.name + ' <' + @commit.author.email + '>'}
+ tr { td ''; td { code @commit.author.date } }
+ tr { td 'committer: '; td @commit.committer.name + ' <' + @commit.committer.email + '>'}
+ tr { td ''; td { code @commit.committer.date } }
+ tr { td 'commit sha: '; td { code @commit.sha } }
+ tr do
+ td 'tree sha: '
+ td do
+ code { a @commit.gtree.sha, :href => R(Tree, @repo, @commit.gtree.sha) }
+ span.space ' '
+ a 'archive', :href => R(Archive, @repo, @commit.gtree.sha)
+ end
+ end
+ tr do
+ td 'parents: '
+ td do
+ @commit.parents.each do |p|
+ code { a p.sha, :href => R(Commit, @repo, p.sha) }
+ span.space ' '
+ a 'diff', :href => R(DiffTwo, @repo, p.sha, @commit.sha)
+ span.space ' '
+ a 'archive', :href => R(Archive, @repo, p.gtree.sha)
+ br
+ end
+ end
+ end
+ end
+ h3 'commit message'
p @commit.message
- p @commit.parent
- p @commit.author.name
- p @commit.author.email
- p @commit.committer.name
- p @commit.committer.email
- p @commit.gtree.sha
+ end
+
+ def tree
+ a.options 'repo', :href => R(View, @repo)
+ h3 'tree : ' + @tree.sha
+ p { a 'archive tree', :href => R(Archive, @repo, @tree.sha) };
+ table do
+ @tree.children.each do |file, node|
+ tr :class => cycle('odd','even') do
+ td { code node.sha[0, 8] }
+ td node.mode
+ td file
+ if node.type == 'tree'
+ td { a node.type, :href => R(Tree, @repo, node.sha) }
+ td { a 'archive', :href => R(Archive, @repo, node.sha) }
+ else
+ td { a node.type, :href => R(Blob, @repo, file, node.sha) }
+ td { a 'raw', :href => R(BlobRaw, @repo, node.sha) }
+ end
+ end
+ end
+ end
+ end
+
+ def blob
+ link :rel => "stylesheet", :type => "text/css",
+ :href => "http://drnicwilliams.com/external/CodeHighlighter/styles.css"
+ script :src => "http://drnicwilliams.com/external/CodeHighlighter/clean_tumblr_pre.js"
+
+ ext = File.extname(@file).gsub('.', '')
+ ext = 'ruby' if ext == 'rb'
+
+ a.options 'repo', :href => R(View, @repo)
+ h3 'blob : ' + @blob.sha
+ h4 @file
+ pre { code @blob.contents, :class => ext }
+ end
+
+ def diff
+ a.options 'repo', :href => R(View, @repo)
+
+ p { a 'patch', :href => R(Patch, @repo, @tree1, @tree2) }
+
+ h1 "diff"
+ p { strong @tree1 + ' : ' + @tree2 }
+
+ @diff.each do |file|
+ h3 file.path
+ pre file.patch
+ end
+ end
+
+
+ def cycle(v1, v2)
+ (@value == v1) ? @value = v2 : @value = v1
+ @value
end
def add