{% extends "repo-full.html" %}
{% import "utils.html" as utils %}
{% block title %}
<title>{{repo.owner.canonical_name}}/{{repo.name}} ({{ ref }}): {{path_join(*path)}} - {{cfg("sr.ht", "site-name")}} git</title>
{% endblock %}
{% block repohead %}
<style>
pre {
  tab-size: {{editorconfig.tab_width()}}
}
</style>
{% endblock %}
{% block content %}
<div class="header-extension mb-0">
  <div class="blob container-fluid">
    <span>
      {{ utils.breadcrumb(ref, commit.id, repo, path, entry, view, path_join, stat, pygit2, humanize, current_user) }}
    </span>
    {% if commit %}
    <div class="commit">
      <a
        href="{{url_for("repo.commit",
          owner=repo.owner.canonical_name,
          repo=repo.name,
          ref=str(commit.id))}}"
        rel="nofollow"
      >{{str(commit.id)[:8]}}</a> &mdash;
      {% set author_user = lookup_user(commit.author.email) %}
      {% if author_user %}
      <a href="{{url_for("public.user_index",
        username=author_user.username)}}">{{commit.author.name}}</a>
      {% else %}
      {{commit.author.name}}
      {% endif %}
      {{trim_commit(commit.message)}}
      <span class="text-muted">
        {{ commit_time(commit) | date }}
      </span>
    </div>
    <div class="clearfix"></div>
    {% endif %}
  </div>
</div>
{% if markdown %}
<div class="container-fluid markdown-nav">
  <ul class="nav nav-tabs">
    <li class="nav-item">
      <a
        class="nav-link {{"active" if not force_source else ""}}"
        href="?view-rendered"
      >View Rendered</a>
    </li>
    <li class="nav-item">
      <a
        class="nav-link {{"active" if force_source else ""}}"
        href="?view-source"
      >View Source</a>
    </li>
  </ul>
</div>
{% endif %}
{% if markdown and not force_source %}
<div class="container">
{% else %}
<div class="container-fluid code-viewport">
{% endif %}
  {#
    This row has some weird styles going on. This prevents the page from
    scrolling horizontally
  #}
  <div class="row mr-0">
    {% if markdown and not force_source %}
    <div class="col-md-10 offset-md-1 mt-3">
      {{ markdown }}
    </div>
    {% else %}
    {% if not blob.is_binary and blob.size < 512000 %}
    <div class="col-md-12 code-view">
      {% autoescape off %}
      <pre class="ruler"><span>{% for i in range(
        editorconfig.max_line_length()) %} {% endfor %}</span></pre>
      {% set lines = data.splitlines()|length %}
      <pre class="lines">{{ linecounter(lines) }}</pre>
      {% endautoescape %}
      {{ highlight_file(repo, ref, entry,
        data, str(blob.id), str(commit.id)) }}
    </div>
    {% elif blob.is_binary %}
    <div class="col-md-12">
      <div class="p-3">
        <p>
          <span title="{{ blob.size }} bytes">
            {{humanize.naturalsize(blob.size,
              binary=True).replace("Byte", "byte")}}
          </span>
          binary file not shown.
        </p>
        <p>
          <a href="{{url_for("repo.raw_blob",
              owner=repo.owner.canonical_name,
              repo=repo.name, ref=ref,
              path=path_join(*path))}}"
              class="btn btn-primary"
              rel="nofollow"
          >Download {{icon("caret-right")}}</a>
        </p>
      </div>
    </div>
    {% else %}
    <div class="col-md-12">
      <div class="p-3">
        <p>
          <span title="{{ blob.size }} bytes">
            {{humanize.naturalsize(blob.size,
              binary=True).replace("Byte", "byte")}}
          </span>
          large file not shown.
        </p>
        <p>
          <a href="{{url_for("repo.raw_blob",
              owner=repo.owner.canonical_name,
              repo=repo.name, ref=ref,
              path=path_join(*path))}}"
              class="btn btn-primary"
              rel="nofollow"
          >Download {{icon("caret-right")}}</a>
        </p>
      </div>
    </div>
    {% endif %}
    {% endif %}
</div>
{% endblock %}

{% block scripts %}
<script src="/static/linelight.js"></script>
{% endblock %}
