gitprep / templates / blob.html.ep /
e7b9307 10 years ago
2 contributor
110 lines | 3.857kb
<%
  use Text::Markdown::Hoedown;
  
  # 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($user, $project, $rev_file);

  # Commit
  my $commit = $git->last_change_commit($user, $project, $rev, $file);

  # Authors
  my $authors = $git->authors($user, $project, $rev, $file);
  
  # Blob lines
  my $lines = $git->blob($user, $project, $rev, $file);

  # File size
  my $file_size = $git->blob_size($user, $project, $rev, $file);
  
  # File mode
  my $mode = $git->blob_mode($user, $project, $rev, $file);
  my $file_type = $git->file_type_long($mode);
  
  # MIME type
  my $mime_type = $git->blob_mime_type($user, $project, $rev, $file);

  # Variables for included template
  stash(id => $rev, project => $project, rev => $rev);
%>

<% layout 'common' , title => "$project/$file at $rev \x{30fb} $user/$project",
     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" style="padding:5px">
        <a style="color:#333;font-weight:bold" href="#" title="<%= $commit->{author_email} %>"><%= $commit->{author_name} %></a>
        <span class="muted" title="<%= $commit->{age_string_datetime_local} %>"><%= $commit->{age_string} %></span>
        <a style="color:#666" href="<%= url_for("/$user/$project/commit/$commit->{id}") %>">
          <%= $commit->{title} %>
        </a>
      </div>
      <div style="padding:5px">
        <b><%= @$authors %></b> <span class="muted">contributor</span>
      </div>
    </div>

    <div class="border-gray bk-gray-light" style="padding:5px">
      <div class="row">
        <div class="span7" style="padding-top:5px">
          <i class="icon-file icon-white"></i>
          <%= $file_type %>
          <span class="muted">|</span>
          <%= @$lines %> lines
          <span class="muted">|</span>
          <%= $file_size %>kb
        </div>
        <div class="text-right">
          <a class="btn" href="<%= url_for("/$user/$project/raw/$rev/$file") %>">Raw</a>
          <a class="btn" href="<%= url_for("/$user/$project/blame/$rev/$file") %>">Blame</a>
          <a class="btn" href="<%= url_for("/$user/$project/commits/$rev/$file") %>">History</a>
        </div>
      </div>
    </div>
    % if ($file =~ /\.md$/) {
        % my $readme = join "\n", @$lines;
        % my $readme_e = Text::Markdown::Hoedown::markdown($readme, extensions => HOEDOWN_EXT_FENCED_CODE);
       <div class="markdown border-gray">
         <%== $readme_e %>
       </div>
    % } elsif ($mime_type =~ m#^image/#) {
      <div style="background:#ddd;text-align:center;padding-top:30px;padding-bottom:30px;margin-bottom:30px">
        <img type="<%= $mime_type %>
          % if (defined $file) {
            alt="<%= $file %>" title="<%= $file %>"
          % }
          src="<%= url_for("/$user/$project/raw/$rev/$file") %>"
        />
      </div>
    % } elsif ($mime_type =~ m#^text/#) {
      <pre class="prettyprint linenums"><% for my $line (@$lines) { %><%= "$line\n" %><% } %></pre>
    % } else {
      <div style="font-size:16px;background:#ddd;text-align:center;padding-top:30px;padding-bottom:30px;margin-bottom:30px">
        <a href="<%= url_for("/$user/$project/raw/$rev/$file") %>">View raw</a>
      </div>
    % }
  </div>
  
  %= javascript '/js/google-code-prettify/prettify.js';
  %= javascript begin
    // Google prety print
    prettyPrint();
  % end
  
  %= include '/include/footer';