Skip to content

Commit

Permalink
improved repository page design
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-kimoto committed Nov 23, 2012
1 parent 13312bd commit 609f0b1
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/Gitpub.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ sub startup {
# Home
$r->get('/')->to('#home');

#User
# Repositories
$r->get('/:user')->to('#repositories');

# Repository
$r->get('/:user/:repository')->to('#repository');

=pod
# Projects
$r->get('/(*home)/projects')->to('#projects')->name('projects');
Expand Down Expand Up @@ -141,6 +145,7 @@ sub startup {
$r->get('/snapshot/(:id)', {id => 'HEAD'})
->to('#snapshot')->name('snapshot');
}
=cut

# File cache
$git->search_projects;
Expand Down
77 changes: 77 additions & 0 deletions lib/Gitpub/Main.pm
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,83 @@ sub log {

has 'root' => '/gitpub';

sub _root_ns {
my $self = shift;

my $root = $self->root;
$root =~ s/^\///;

return $root;
}

sub repository {
my $self = shift;

# Parameters
my $user = $self->param('user');
my $repository = $self->param('repository');
my $root_ns = $self->_root_ns;

my $project_ns = "$root_ns/$user/$repository.git";
my $project = "/$project_ns";
my $home_ns = dirname $project_ns;
my $home = "/$home_ns";
my $id_dir = $self->param('id_dir') || 'master/';

# Id and directory
my ($id, $dir) = $self->_parse_id_path($project, $id_dir);

# Git
my $git = $self->app->git;

# Tree id
my $tid;
my $commit = $git->parse_commit($project, $id);
unless (defined $tid) {
if (defined $dir && $dir ne '') {
$tid = $git->id_by_path($project, $id, $dir, 'tree');
}
else { $tid = $commit->{tree} }
}
$self->render_not_found unless defined $tid;

# Get tree (command "git ls-tree")
my @entries = ();
my $show_sizes = 0;
open my $fh, '-|', $git->cmd($project), 'ls-tree', '-z',
($show_sizes ? '-l' : ()), $tid
or croak 'Open git-ls-tree failed';
local $/ = "\0";
@entries = map { chomp; $git->dec($_) } <$fh>;
close $fh
or croak 404, "Reading tree failed";

# Parse tree
my @trees;
for my $line (@entries) {
my $tree = $git->parse_ls_tree_line($line, -z => 1, -l => $show_sizes);
$tree->{mode_str} = $git->_mode_str($tree->{mode});
push @trees, $tree;
}

# References
my $refs = $git->references($project);

# Render
$self->render(
home => $home,
home_ns => $home_ns,
project => $project,
project_ns => $project_ns,
dir => $dir,
id => $id,
tid => $tid,
commit => $commit,
trees => \@trees,
refs => $refs
);
}

sub repositories {
my $self = shift;

Expand Down
6 changes: 5 additions & 1 deletion public/gitweb.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
* {
margin:0;
padding:0;
}

body {
font-family: sans-serif;
font-size: 100%;
border: solid #d9d8d1;
border-width: 1px;
margin: 10px;
background-color: #ffffff;
color: #000000;
}
Expand Down
22 changes: 22 additions & 0 deletions templates/include/new_header.html.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
%= stylesheet begin
#header {
margin-bottom:10px;
border-bottom:1px solid black;
height:40px;
}

#header li{
float:left;
padding: 10px 20px;
}
% end
<div id="header">
<ul>
<li><a href="<%= url_for('/') %>">Home</a></li>
<li><a href="<%= url_for("/$user") %>"><%= $user %></a></li>
<li><a href="<%= url_for("/new") %>">Create a new repo</a></li>
<li><a href="<%= url_for("/setting/profile") %>">Account setting</a></li>
<li><a href="<%= url_for("/logout") %>">Sign out</a></li>
</ul>
</div>
<div style="clear:both"/>
81 changes: 81 additions & 0 deletions templates/main/repository.html.ep
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
% layout 'common';
%= include '/include/new_header';

%= stylesheet begin
#menu-item li {
float:left;
border: 1px solid black;
padding: 10px 20px;
margin-bottom:10px;
}
.clear {
clear:both;
}
% end

<div>
<a href="<%= url_for("/$user") %>"><%= $user %></a> / <%= $repository %>
</div>

<ul id="menu-item">
<li>Code</li>
<li>Issues</li>
<li>Wiki</li>
<li>Admin</li>
</ul>

<div class="header" style="clear:both">
<a class="title" href="<%= url_for('commit', project => $project_ns, id => $id) %>">
<%= $commit->{title} %>
</a>
</div>

%= include '/include/page_path', project_ns => $project_ns, id => $id, Path => $dir, type => 'tree';

<div class="page_body">
%= include 'include/refs', project => $project_ns, commit => $commit, refs => $refs;
<table class="tree">
% for (my $i = 0; $i <@$trees; $i++) {

% my $tree = $trees->[$i];
% my $type = $tree->{type};
% my $name = $tree->{name};

% my $child_dir = defined $dir && length $dir ? join('/', $dir, $name) : $name;
<tr class="<%= $i % 2 ? 'light' : 'dark' %>">
<td class="mode">
<%= $tree->{mode_str} %>
</td>
% my $file = defined $dir ? "$dir/$name" : $name;
% $file =~ s/^\///;

<td class="list">
% if ($type eq 'blob') {
<a class="list" href="<%= url_for('blob', project => $project_ns, id_file => "$id/$file") %>">
<%= $name %>
</a>
% } elsif ($tree) {
<a href="<%= url_for('tree', project => $project_ns, id_dir => "$id/$child_dir") %>">
<%= $name %>
</a>
% }
</td>
<td class="link">
% if ($type eq 'blob') {
<a href="<%= url_for('blob', project => $project_ns, id_file => "$id/$file") %>">
blob
</a>
|
<a href="<%= url_for('blob_plain', project => $project_ns, id_file => "$id/$file") %>">
raw
</a>
% } elsif ($type eq 'tree') {
<a href="<%= url_for('tree', project => $project_ns, id_dir => "$id/$child_dir") %>">
tree
</a>
% }
</td>
</tr>
% }
</table>
</div>

0 comments on commit 609f0b1

Please sign in to comment.