gitprep / templates / blob.html.ep /
e75d147 8 years ago
3 contributor
130 lines | 4.055kb
<%
  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);
  
  # 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);

  # Blob lines(only text)
  my $lines;
  $lines = $git->blob($user, $project, $rev, $file) if $mime_type =~ /^text/;

  # 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">
    <div style="margin-bottom:20px;">
      %= include '/include/branch_select', display => 'blob', Path => $file;
    </div>

    <div class="commit-summary">
      <div class="commit-summary-left-container">
        <span class="commit-summary-author" title="<%= $commit->{author_email} %>"><%= $commit->{author_name} %></span>
        <a href="<%= url_for("/$user/$project/commit/$rev") %>">
          <%= $commit->{title} %>
        </a>
      </div>
      <div class="commit-summary-right-container">
        <a href="<%= url_for("/$user/$project/commit/$commit->{id}") %>">
          <%= substr($commit->{id}, 0, 7) %>
        </a>
        <%= $commit->{age_string} %>
      </div>
    </div>
          
    <div class="commit-contributor">
      <%= @$authors %> contributor
    </div>

    <div>
      <div class="file-header">
        <div class="file-header-left">
          % if ($lines) {
            <%= @$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>
            % if ($mime_type =~ m#^text/#) {
              <li>
                <a class="btn btn-small" href="<%= url_for("/$user/$project/blame/$rev/$file") %>">Blame</a>
              </li>
            % }
            <li>
              <a class="btn btn-small" href="<%= url_for("/$user/$project/commits/$rev/$file") %>">History</a>
            </li>
          </ul>
        </div>
      </div>
    </div>
    % if ($mime_type =~ m#^image/#) {
      <div class="blob-image">
        <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/#) {
      % if ($file =~ /\.md$/) {
        % my $readme = join "\n", @$lines;
        % $readme =~ s#^(\[.*\]:)(?!\s*https?://)\s*(\S*)#$1 /$user/$project/raw/$rev/$2#mg;
        % $readme =~ s#^(!\[.*\]\()(?!https?://)(\S*)#$1/$user/$project/raw/$rev/$2#mg;
        % my $readme_e = Text::Markdown::Hoedown::markdown($readme, extensions => HOEDOWN_EXT_FENCED_CODE);
        <div class="markdown-body border-gray">
          <%== $readme_e %>
        </div>
      % } else {
        <pre class="prettyprint linenums"><% for my $line (@$lines) { %><%= "$line\n" %><% } %></pre>
      % }
    % } else {
      <div class="blob-raw">
        <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';