gitprep / templates / blame.html.ep /
Yuki Kimoto cleanup methods
dba3c65 8 years ago
1 contributor
137 lines | 4.572kb
<%
  # API
  my $api = gitprep_api;

  # Git
  my $git = $self->app->git;
  
  # Parameters
  my $user = param('user');
  my $project = param('project');
  my $rev_file = param('rev_file');
  my ($rev, $file) = $git->parse_rev_path(app->rep_info($user, $project), $rev_file);

  # Commit
  my $commit = $git->last_change_commit(app->rep_info($user, $project), $rev, $file);
  
  # Authors
  my $authors = $git->authors(app->rep_info($user, $project), $rev, $file);
  
  # File size
  my $file_size = $git->blob_size(app->rep_info($user, $project), $rev, $file);

  # File mode
  my $mode = $git->blob_mode(app->rep_info($user, $project), $rev, $file);
  my $file_type = $git->file_type_long($mode);

  # MIME type
  my $mime_type = $git->blob_mime_type(app->rep_info($user, $project), $rev, $file);

  # Blame
  my $blame = $git->blame(app->rep_info($user, $project), $rev, $file);
  my $blame_lines = $blame->{lines};
  my $blame_min_author_time = $blame->{min_author_time};
  my $blame_max_author_time = $blame->{max_author_time};
  
  # Color
  my $colors = [
    '#ffeca7',
    '#ffdd8c',
    '#ffdd7c',
    '#fba447',
    '#f68736',
    '#f37636',
    '#ca6632',
    '#c0513f',
    '#a2503a',
    '#793738'
  ];
  
  # Variables for included template
  stash(id => $rev, project => $project, rev => $rev);
%>

% layout 'common' , title => "$user/$project at $rev";

  %= include '/include/header';
  
  <!-- Blame page -->
  <div class="container">
    <div class="blame-page-path">
      %= include '/include/page_path', Path => $file;
      <div class="blame-gradation">
        Newer
        % for my $color (@$colors) {
          <span style="font-size:20px;color:<%= $color %>">■</span>
        % }
        Older
      </div>
    </div>
    <div class="file-header">
      <div class="file-header-left">
        <i class="icon-file icon-white"></i>
        <%= @$blame_lines %> lines
        <span style="color:#dcdcdc">|</span>
        <%= $file_size %>kb
      </div>
      <div class="file-header-right">
        <ul>
          <li>
            <a class="btn btn-small" href="<%= url_for("/$user/$project/raw/$rev/$file") %>">Raw</a>
          </li>
          <li>
            <a class="btn btn-small" href="<%= url_for("/$user/$project/blob/$rev/$file") %>">Normal View</a>
          </li>
          <li>
            <a class="btn btn-small" href="<%= url_for("/$user/$project/commits/$rev/$file") %>">History</a>
          </li>
        </ul>
      </div>
    </div>
    <div class="blame-body-container">
      <table class="blame-body">
        % for my $line (@$blame_lines) {
          <%
            my $blame_commit = $line->{commit};
            my $summary = $line->{summary};
            my $summary_short= length $summary > 28 ? substr($summary, 0, 28) . '...' : $summary;
            my $time_rate = $blame_max_author_time == $blame_min_author_time
             ? 1
             : ($blame_max_author_time - $line->{author_time}) / ($blame_max_author_time - $blame_min_author_time);
            my $color_number = int($time_rate * 10);
            $color_number = 9 if $color_number == 10;
            my $hot_color = $colors->[$color_number];
          %>
          <tr id="L<%= $line->{number} %>">
            % if ($line->{before_same_commit}) {
              <td class="blame-body-left" nowrap style="border-right:2px solid <%= $hot_color %>"></td>
            % } else {
              <td class="blame-body-left" nowrap style="border-right:2px solid <%= $hot_color %>">
                <div class="blame-summary-container">
                  <div class="blame-summary">
                    <%= $summary_short %>
                  </div>
                  <div class="blame-commit-id">
                    <a href="<%= url_for("/$user/$project/commit/$blame_commit") %>" ><%= substr($blame_commit, 0, 7) %></a>
                  </div>
                </div>
                <div class="blame-author">
                  <span title="<%= $line->{author_mail} %>"><%= $line->{author} %></span>
                  authored on
                  <%= $line->{author_age_string_date_local} %>
                </div>
              </td>
            % }
            <td class="blame-body-center" nowrap>
              <%= $line->{number} %>
            </td>
            <td nowrap class="blame-body-right">
              <pre style="border:none;background:white;margin:0;padding:0;white-space: nowrap;"><%= $line->{content} %></pre>
            </td>
          </tr>
        % }
      </table>
    </div>
  </div>
  
  %= include '/include/footer';