Get blob view working again
Tomas Doran [Mon, 18 Jan 2010 01:23:40 +0000 (01:23 +0000)]
lib/Gitalist/Controller/Fragment/Commit.pm
lib/Gitalist/Controller/Root.pm
root/commit/blob.tt2 [moved from root/blob.tt2 with 73% similarity]
root/fragment/commit/blob.tt2 [new file with mode: 0644]

index 12e86ad..b39b9ef 100644 (file)
@@ -55,7 +55,6 @@ after blame => sub {
 
     my $repository = $c->stash->{Repository};
     my $filename = join('/', @fn);
-
                                                       # WTF?
     my $blame = $c->stash->{Commit}->blame($filename, $c->stash->{Commit}->sha1);
     $c->stash(
@@ -71,4 +70,30 @@ after blame => sub {
         unless $c->stash->{no_wrapper};
 };
 
+=head2 blob
+
+The blob action i.e the contents of a file.
+
+=cut
+
+after blob => sub {
+    my ( $self, $c, @fn ) = @_;
+
+    my $filename = join('/', @fn);
+    my $repository = $c->stash->{Repository};
+    my $h  =
+          $repository->hash_by_path($c->stash->{Commit}->sha1, $filename)
+          || die "No file or sha1 provided.";
+     my $blob = $repository->get_object($h);
+    $c->stash(
+        blob     => $blob->content,
+        filename => $filename,
+        # XXX Hack hack hack, see View::SyntaxHighlight
+        language => ($filename =~ /\.p[lm]$/i ? 'Perl' : ''),
+    );
+
+    $c->forward('View::SyntaxHighlight')
+        unless $c->stash->{no_wrapper};
+};
+
 __PACKAGE__->meta->make_immutable;
index b2223ec..b20ebc1 100644 (file)
@@ -73,27 +73,7 @@ sub _blob_objs {
   return $blob, $repository->get_object($hb), $filename;
 }
 
-=head2 blob
 
-The blob action i.e the contents of a file.
-
-=cut
-
-sub blob : Chained('base') Args(0) {
-  my ( $self, $c ) = @_;
-
-  my($blob, $head, $filename) = $self->_blob_objs($c);
-  $c->stash(
-    blob     => $blob->content,
-    head     => $head,
-    filename => $filename,
-    # XXX Hack hack hack, see View::SyntaxHighlight
-    language => ($filename =~ /\.p[lm]$/i ? 'Perl' : ''),
-  );
-
-  $c->forward('View::SyntaxHighlight')
-    unless $c->stash->{no_wrapper};
-}
 
 =head2 blob_plain
 
similarity index 73%
rename from root/blob.tt2
rename to root/commit/blob.tt2
index 06077b2..994b9d7 100644 (file)
@@ -9,6 +9,6 @@
   [% END %]
   [% INCLUDE 'nav/path.tt2' %]
   <div>
-   <pre class='blob'>[% blob %]</pre>
+   <pre class='blob'>[% subinclude('/fragment/commit/blob', c.req.captures, c.req.args.to_path) %]</pre>
   </div>
 </div>
diff --git a/root/fragment/commit/blob.tt2 b/root/fragment/commit/blob.tt2
new file mode 100644 (file)
index 0000000..592f8c5
--- /dev/null
@@ -0,0 +1 @@
+[% blob %]