Add a repo profile, pretty stupid right now (using HEAD)

This commit is contained in:
R. Tyler Croy 2011-11-06 00:30:49 -07:00
parent add7bc8ec8
commit ea69fc18ca
4 changed files with 115 additions and 0 deletions

11
app.rb
View File

@ -25,3 +25,14 @@ get "/:username" do |username|
haml :profile
end
get "/:username/:repo" do |username, repo|
@username = username
@reponame = repo
@tree = @api.tree_for(username, repo)["tree"]
@tree.sort! do |left, right|
left["type"] <=> right["type"]
end
@uri_base = "https://github.com/#{username}/#{repo}/blob/HEAD"
haml :repo
end

View File

@ -12,6 +12,7 @@ module RCSHub
attr_accessor :cache
REPOS_CACHE_KEY = "repos-for:"
TREE_CACHE_KEY = "tree-for:"
CACHE_EXPIRE = 60 * 5
@ -34,12 +35,30 @@ module RCSHub
return result
end
def tree_for(username, repo)
key = "#{TREE_CACHE_KEY}#{username}"
unless @cache.nil?
if result = @cache.get(key)
return JSON.load(result)
end
end
result = fetch_tree_for(username, repo)
@cache.setex(key, CACHE_EXPIRE, JSON.dump(result)) unless @cache.nil?
return result
end
private
def fetch_repos_for(username)
return self.class.get("#{BASE_URL}/users/#{username}/repos")
end
def fetch_tree_for(username, repo)
return self.class.get("#{BASE_URL}/repos/#{username}/#{repo}/git/trees/HEAD")
end
end
end
end

BIN
public/icons/unknown.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

85
views/repo.haml Normal file
View File

@ -0,0 +1,85 @@
%html
%head
%title= "Index of /#{@username}/#{@reponame}"
%body
%h1
Index of /#{@username}/#{@reponame}
%table
%tr
%th
%img{:src => "/icons/blank.png"}
%th
%a{:href => "#"}
Name
%th
%a{:href => "#"}
Last Modified
%th
%a{:href => "#"}
Size
%th
%a{:href => "#"}
Description
%tr
%th{:colspan => 5}
%hr
%tr
%td
%img{:src => "/icons/back.png"}
%td
%a{:href => "/#{@username}"}
Parent Directory
%td
%td{:align => "right"}
\-
%tr
%td
%img{:src => "/icons/folder.png"}
%td
%a{:href => "/#{@username}/#{@reponame}/branches"}
branches
%td
%td{:align => "right"}
\-
%tr
%td
%img{:src => "/icons/folder.png"}
%td
%a{:href => "/#{@username}/#{@reponame}/tags"}
tags
%td
%td{:align => "right"}
\-
%tr
%td
%img{:src => "/icons/tar.png"}
%td
%a{:href => "/#{@username}/#{@reponame}/clone"}
clone #{@reponame.downcase}.rcsrepo
%td
%td{:align => "right"}
\-
%tr
%th{:colspan => 5}
%hr
- @tree.reverse_each do |f|
%tr{:class => "tree_file_row"}
%td
- if f["type"] == "tree"
%img{:src => "/icons/folder.png"}
- else
%img{:src => "/icons/unknown.png"}
%td
%a{:href => "#{@uri_base}/#{f["path"]}"}
#{f["path"]}
%td
&nbsp;
%td{:align => "right"}
- if f["type"] == "tree"
\-
- else
#{f["size"]}
%td
&nbsp;