The list of projects is now in working order, but nothing else.
Dan Brook [Tue, 8 Sep 2009 11:39:33 +0000 (12:39 +0100)]
lib/Gitalist.pm
lib/Gitalist/Controller/Root.pm
lib/Gitalist/Model/Git.pm
templates/index.tt2 [new file with mode: 0644]

index 978170d..16e0990 100644 (file)
@@ -8,7 +8,8 @@ extends 'Catalyst';
 
 use Catalyst qw/-Debug
                 ConfigLoader
-                Static::Simple/;
+                Static::Simple
+                               StackTrace/;
 our $VERSION = '0.01';
 
 # Bring in the libified gitweb.cgi.
index 365b5a5..c6f3a84 100644 (file)
@@ -40,8 +40,6 @@ sub default :Path {
   };
   $capture->stop();
 
-  gitweb::git_header_html();
-  gitweb::git_footer_html();
   my $output = join '', $capture->read;
   $c->stash->{content} = $output
     unless $c->stash->{content};
@@ -49,26 +47,18 @@ sub default :Path {
 }
 
 sub index :Path :Args(0) {
-    my ( $self, $c ) = @_;
-
-  my $order = $c->req->param('order');
-  if($order && $order !~ m/none|project|descr|owner|age/) {
-    die "Unknown order parameter";
-  }
+  my ( $self, $c ) = @_;
 
-  my @list = $c->model('Git')->list_projects;
-  if (!@list) {
+  my $list = $c->model('Git')->list_projects;
+  unless(@$list) {
     die "No projects found";
   }
 
-  if (-f $c->config->{home_text}) {
-    $c->stash->{home_text_contents} = slurp($c->config->{home_text});
-  }
-
-  $c->config->{ENV} = \%ENV;
-  $c->stash->{searchtext} = $c->req->param('searchtext');
-  $c->stash->{projects}   = \@list;
-  $c->stash->{action}     = 'index';
+  $c->stash(
+    searchtext => $c->req->param('searchtext') || '',
+    projects   => $list,
+    action     => 'index',
+  );
 }
 
 sub auto : Private {
@@ -178,8 +168,8 @@ sub footer {
   my @feeds;
   my $project = $c->req->param('project')  || $c->req->param('p');
        if(defined $project) {
-    # ... this could be simpler ...            # Chop off .git
-               my $descr = $c->model('Git')->project_info(substr($project, 0, -5))->{description};
+    (my $pstr = $project) =~ s[/?\.git$][];
+               my $descr = $c->model('Git')->project_info($project)->{description};
                $c->stash->{project_description} = defined $descr
                        ? encode_entities($descr)
                        : '';
index d96d1aa..902b331 100644 (file)
@@ -42,8 +42,7 @@ EOR
 sub is_git_repo {
     my ($self, $dir) = @_;
 
-    #FIXME: Only handles bare repos. Is that enough?
-    return -f $dir->file('HEAD') or -f $dir->file('.git/HEAD');
+    return -f $dir->file('HEAD') || -f $dir->file('.git/HEAD');
 }
 
 sub project_info {
@@ -70,7 +69,6 @@ sub get_project_properties {
         delete $props{description};
     }
 
-       #Carp::cluck "dir is: $dir";
     $props{owner} = (getpwuid $dir->stat->uid)[6];
 
     my $output = $self->run_cmd_in($dir, qw{
@@ -100,9 +98,12 @@ sub list_projects {
         my $obj = $base->subdir($file);
         next unless -d $obj;
         next unless $self->is_git_repo($obj);
+               # XXX Leaky abstraction alert!
+               $obj = $obj->subdir('.git')
+                       if -d $obj->subdir('.git');
 
         push @ret, {
-            name => ($obj->dir_list)[-1],
+            name => (File::Spec->splitdir($base->subdir($file)))[-1],
             $self->get_project_properties($obj),
         };
     }
@@ -139,8 +140,6 @@ sub run_cmd_in {
 sub git_dir_from_project_name {
     my ($self, $project) = @_;
 
-       warn 'er, dir    - '.dir(Gitalist->config->{repo_dir});
-       warn 'er, subdir - '.dir(Gitalist->config->{repo_dir})->subdir($project);
     return dir(Gitalist->config->{repo_dir})->subdir($project);
 }
 
diff --git a/templates/index.tt2 b/templates/index.tt2
new file mode 100644 (file)
index 0000000..8134ae1
--- /dev/null
@@ -0,0 +1,41 @@
+[% IF home_text_contents %]
+<div class="index_include">
+  [% home_text_contents %]
+</div>
+[% END %]
+
+<form method="get" action="/" enctype="application/x-www-form-urlencoded">
+<p class="projsearch">Search:
+<input type="text" name="s" value="[% search_text %]" />
+</p>
+</form>
+
+<table class="project_list">
+<thead>
+    <tr>
+        <th>Project</th>
+        <th><a class="header" href="/projects?o=descr">Description</a></th>
+        <th><a class="header" href="/projects?o=owner">Owner</a></th>
+        <th><a class="header" href="/projects?o=age">Last Change</a></th>
+        <th></th>
+    </tr>
+</thead>
+
+<tbody>
+  [%
+    USE Cycle('dark', 'light');
+    FOR p IN projects %]
+    <tr class="[% Cycle.next %]">
+        <td><a class="list" href="/?p=[% p.name %];a=summary">[% p.name %]</a></td>
+        <td><a class="list" title="[% p.description %]" href="/?p=[% p.name %];a=summary">[% p.description.substr(0, 20) %]</a></td>
+        <td>[% p.owner %]</td>
+        <td class="age2">[% p.last_change %]</td>
+        <td class="link"><a href="/?p=[% p.name %];a=summary">summary</a>
+            | <a href="/?p=[% p.name %];a=shortlog">shortlog</a>
+            | <a href="/?p=[% p.name %];a=log">log</a>
+            | <a href="/?p=[% p.name %];a=tree">tree</a></td>
+    </tr>
+  [% END %]
+</tbody>
+
+</table>