Get blame view working in the new url scheme
Tomas Doran [Mon, 18 Jan 2010 00:53:01 +0000 (00:53 +0000)]
lib/Gitalist/Controller/Fragment/Commit.pm
lib/Gitalist/Controller/Root.pm
root/commit/blame.tt2 [new file with mode: 0644]
root/fragment/commit/blame.tt2 [moved from root/blame.tt2 with 64% similarity]

index 81f75d3..12e86ad 100644 (file)
@@ -50,4 +50,25 @@ after tree => sub {
     );
 };
 
+after blame => sub {
+    my($self, $c, @fn) = @_;
+
+    my $repository = $c->stash->{Repository};
+    my $filename = join('/', @fn);
+
+                                                      # WTF?
+    my $blame = $c->stash->{Commit}->blame($filename, $c->stash->{Commit}->sha1);
+    $c->stash(
+        blame    => $blame,
+        filename => $filename,
+
+        # XXX Hack hack hack, see View::SyntaxHighlight
+        language => ($filename =~ /\.p[lm]$/i ? 'Perl' : ''),
+        blob     => join("\n", map $_->{line}, @$blame),
+    );
+
+    $c->forward('View::SyntaxHighlight')
+        unless $c->stash->{no_wrapper};
+};
+
 __PACKAGE__->meta->make_immutable;
index 7190b05..b2223ec 100644 (file)
@@ -53,33 +53,6 @@ sub index : Chained('base') PathPart('') Args(0) {
   );
 }
 
-sub blame : Chained('base') Args(0) {
-  my($self, $c) = @_;
-
-  my $repository = $c->stash->{Repository};
-  my $h  = $c->req->param('h')
-       || $repository->hash_by_path($c->req->param('hb'), $c->req->param('f'))
-       || die "No file or sha1 provided.";
-  my $hb = $c->req->param('hb')
-       || $repository->head_hash
-       || die "Couldn't discern the corresponding head.";
-  my $filename = $c->req->param('f') || '';
-
-  my $blame = $repository->get_object($hb)->blame($filename, $h);
-  $c->stash(
-    blame    => $blame,
-    head     => $repository->get_object($hb),
-    filename => $filename,
-
-    # XXX Hack hack hack, see View::SyntaxHighlight
-    language => ($filename =~ /\.p[lm]$/i ? 'Perl' : ''),
-    blob     => join("\n", map $_->{line}, @$blame),
-  );
-
-  $c->forward('View::SyntaxHighlight')
-    unless $c->stash->{no_wrapper};
-}
-
 sub _blob_objs {
   my ( $self, $c ) = @_;
   my $repository = $c->stash->{Repository};
diff --git a/root/commit/blame.tt2 b/root/commit/blame.tt2
new file mode 100644 (file)
index 0000000..868b73e
--- /dev/null
@@ -0,0 +1,37 @@
+[%- BLOCK blame_table_headfoot %]
+<tr>
+ <td>author</td>
+ <td>date</td>
+ <td>sha1</td>
+ <td></td>
+ <td class='data'>data</td>
+</tr>
+[% END -%]
+[% PROCESS 'nav/actions.tt2' object = head %]
+[%- INCLUDE inc/syntax_highlight_css.tt2 -%]
+
+<div class='content'>
+
+[% IF object.type == 'commit' %]
+<div class='commit-message'>[% short_cmt(head.comment) %]</div>
+[% END %]
+
+[% INCLUDE 'nav/path.tt2' %]
+
+<div id='blame'>
+<table>
+ <thead>
+  [% PROCESS blame_table_headfoot %]
+ </thead>
+
+ <tfoot>
+   [% PROCESS blame_table_headfoot %]
+ </tfoot>
+
+ <tbody>
+ [% subinclude('/fragment/commit/blame', c.req.captures, c.req.arguments.to_path ) %]
+ </tbody>
+</table>
+</div>
+
+</div>
similarity index 64%
rename from root/blame.tt2
rename to root/fragment/commit/blame.tt2
index 19d3e61..75f139e 100644 (file)
@@ -1,38 +1,4 @@
-[% PROCESS 'nav/actions.tt2' object = head %]
-[% INCLUDE inc/syntax_highlight_css.tt2 %]
-
-<div class='content'>
-
-[% IF object.type == 'commit' %]
-<div class='commit-message'>[% short_cmt(head.comment) %]</div>
-[% END %]
-
-[% INCLUDE 'nav/path.tt2' %]
-
-<div id='blame'>
-<table>
- <thead>
-  <tr>
-   <th>author</th>
-   <th>date</th>
-   <th>sha1</th>
-   <th></th>
-   <th class='data'>data</th>
-  </tr>
- </thead>
-
- <tfoot>
-  <tr>
-   <td>author</td>
-   <td>date</td>
-   <td>sha1</td>
-   <td></td>
-   <td class='data'>data</td>
-  </tr>
- </tfoot>
-
- <tbody>
- [% blame_lines = blob.split("\n") %]
+[% blame_lines = blob.split("\n") %]
  [% FOR info IN blame %]
  <tr class=''>
    [%-
@@ -52,8 +18,3 @@
    [% lastsha1 = info.commit.sha1 %]
  </tr>
  [% END %]
- </tbody>
-</table>
-</div>
-
-</div>