Clean up Root::end action, and properly handle missing project descriptions.
Zachary Stevens [Wed, 4 Nov 2009 23:41:00 +0000 (23:41 +0000)]
lib/Gitalist/Controller/Root.pm
lib/Gitalist/Git/Project.pm
lib/Gitalist/Git/Util.pm

index 6381a8e..af8cfb6 100644 (file)
@@ -546,6 +546,7 @@ sub feed_info {
 
   return %res;
 }
+
 =head2 end
 
 Attempt to render a view, if needed.
@@ -553,22 +554,24 @@ Attempt to render a view, if needed.
 =cut
 
 sub end : ActionClass('RenderView') {
-  # Give every view the current HEAD.
-  $_[1]->stash->{HEAD} = $_[1]->model()->head_hash;
-  
-  # XXX Move this into a plugin!
-  use DateTime::Format::Human::Duration;
-  $_[1]->stash->{time_since} = sub {
-    my($dt, $now) = ($_[0], DateTime->now);
-
-    my($age) = $dt < (DateTime->now - DateTime::Duration->new(days=>12))
-      ? $dt->ymd
-      : DateTime::Format::Human::Duration->new->format_duration($now - $dt)
-          =~ /^(?:.*?weeks?, )?(\d+ [^\d]+)(?:,|$) /;
-
-    
-    return $age;
-  };
+    my ($self, $c) = @_;
+    # Give project views the current HEAD.
+    if ($c->stash->{project}) {
+        $c->stash->{HEAD} = $c->model()->head_hash;
+    }
+
+    # XXX Move this into a plugin!
+    use DateTime::Format::Human::Duration;
+    $c->stash->{time_since} = sub {
+        my($dt, $now) = ($self, DateTime->now);
+
+        my($age) = $dt < (DateTime->now - DateTime::Duration->new(days=>12))
+            ? $dt->ymd
+                : DateTime::Format::Human::Duration->new->format_duration($now - $dt)
+                    =~ /^(?:.*?weeks?, )?(\d+ [^\d]+)(?:,|$) /;
+
+        return $age;
+    };
 }
 
 =head1 AUTHOR
index eda7d6d..ef818aa 100644 (file)
@@ -35,14 +35,18 @@ class Gitalist::Git::Project {
 
     method _build__util {
         my $util = Gitalist::Git::Util->new(
-            gitdir => $self->path,
+            gitdir => $self->project_dir($self->path),
         );
         return $util;
     }
     
     method _build_description {
-        my $description = $self->path->file('description')->slurp;
-        chomp $description;
+        my $description;
+        eval {
+            $description = $self->path->file('description')->slurp;
+            chomp $description;
+        };
+        $description ||= " ";
         return $description;
     }
 
index c3970fb..68fa266 100644 (file)
@@ -4,7 +4,7 @@ class Gitalist::Git::Util {
     use File::Which;
     use Git::PurePerl;
     use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
-    has gitdir => ( isa => "Path::Class::Dir", is => 'ro' );
+    has gitdir => ( isa => "Str", is => 'ro', required => 1 );
     has _git      => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 );
     sub _build__git {
         my $git = File::Which::which('git');