gitprep / templates / blob.html.ep /
733b93b 11 years ago
1 contributor
112 lines | 3.054kb
<%
  # API
  my $api = gitprep_api;
  
  # Parameters
  my $user = param('user');
  my $project = param('project');
  my $rev = param('rev');
  my $file = param('file');

  # Git
  my $git = $self->app->git;

  # Commit log
  my $commit_log = $git->latest_commit_log($user, $project, $rev, $file);

  # Commit
  my $commit = $git->parse_commit($user, $project, $rev);
  
  # Authors
  my $authors = $git->authors($user, $project, $rev, $file);
  
  # Blob content
  my $bid = $git->id_by_path($user, $project, $rev, $file, 'blob')
    or $api->croak('Cannot find file');
  my @cmd = $git->cmd(
    $user,
    $project,
    'cat-file',
    'blob',
    $bid
  );
  open my $fh, '-|', @cmd
    or $api->croak(qq/Couldn't cat "$file", "$bid"/);
  
  # Blob info
  my $file_size = $git->blob_size_kb($user, $project, $rev, $file);
  my $mimetype = $git->blob_mimetype($fh, $file);

  # Parse line
  my $lines =[];
  while (my $line = $git->dec(scalar <$fh>)) {
    chomp $line;
    $line = $git->_tab_to_space($line);
    push @$lines, $line;
  }
  
  # Variables for included template
  stash(id => $rev, project => $project);
%>

% layout 'common' , stylesheets => ['/js/google-code-prettify/prettify.css'];

  %= include '/include/header';

  <div class="container">
    %= include '/include/project_header';
    %= include '/include/code_menu', display => 'files';
    %= include '/include/page_path', type => 'blob', Path => $file;
        
    <div class="border-gray" style="margin-bottom:20px">
      <div class="bk-blue-light padding5">
        <%= $commit_log->{author} %>
        <span class="muted"><%= $commit_log->{author_date} %></span>
        <a href="<%= url_for("/$user/$project/commit/$rev") %>">
          <%= $commit->{title} %>
        </a>
      </div>
      <div class="padding5">
        <%= @$authors %> contributor
      </div>
    </div>

    <div class="border-gray bk-gray-light padding5">
      <div class="row">
        <div class="span7" style="padding-top:5px">
          <i class="icon-file icon-white"></i>
          <span style="color:gray">|</span>
          <%= @$lines %> lines
          <span style="color:gray">|</span>
          <%= $file_size %>kb
        </div>
        <div class="span4 offset1-mini text-right">
          <a class="btn" href="<%= url_for("/$user/$project/raw/$rev/$file") %>">Raw</a><a class="btn" href="<%= url_for("/$user/$project/commits/$rev/$file") %>">History</a>
        </div>
      </div>
    </div>
    % if ($mimetype =~ m#^image/#) {
      <div>
        <img type="<%= $mimetype %>
          % if (defined $file) {
            alt="<%= $file %>" title="<%= $file %>"
          % }
          src="<%= url_for("/$user/$project/raw/$rev/$file") %>"
        />
      </div>
    % } else {
      <pre class="prettyprint linenums">
        % for my $line (@$lines) {
%= $line;
        % }
      </pre>
    % }
  </div>
  
  %= javascript '/js/google-code-prettify/prettify.js';
  %= javascript begin
    // Google prety print
    prettyPrint();
  % end
  
  %= include '/include/footer';