index : gitrs
A lightweight web interface for browsing Git repositories, implemented in Rust
about summary refs log tree commit diff
gitrs / templates / macros.html
-rw-r--r-- blob 7047cff43daeed8335a9e1306324845985211368 10175 bytes (plain)
1
{% macro header(repo: Option<&Repository> = None, branches: Vec<String> = Vec::new(), current_ref: Option<&Ref> = None) %}
2
  {% if let Some(repo) = repo && let Some(current_ref) = current_ref %}
3
    <tr>
4
      <td class="logo" rowspan="2"><a href="/"><img src="/static/logo.png" width="64" height="64" alt="logo"></a></td>
5
      <td class="main"><a href="/">index</a> : <a title="{{ repo.name }}" href="/{{ repo.name }}/">{{ repo.name }}</a></td>
6
      <td class="form">
7
        <form method="get">
8
          <select name="h" onchange="this.form.submit();">
9
            {% for branch in branches %}
10
              <option value="{{ branch }}" {% if branch == &current_ref.name %}selected{% endif %}>{{ branch }}</option>
11
            {% endfor %}
12
          </select>
13
          <input type="submit" value="switch">
14
        </form>
15
      </td>
16
    </tr>
17
    <tr>
18
      <td class="sub" colspan="2">{{ repo.description }}</td>
19
    </tr>
20
  {% else %}
21
    <tr>
22
      <td class="logo" rowspan="2"><a href="/"><img src="/static/logo.png" width="64" height="64" alt="logo"></a></td>
23
      <td class="main">y2w8 Repos</td>
24
    </tr>
25
    <tr>
26
      <td class="sub">y2w8 git repositories, powered by rsgit</td>
27
    </tr>
28
  {% endif %}
29
{% endmacro %}
30
31
{% macro repo_tabs(repo: Repository, current_ref: Ref, query: PageQuery, active: str) %}
32
  <tr>
33
    <td>
34
      <a href="/{{ repo.name }}/about/{{ query.head_param() }}" class="{% if active == "about" %}active{% endif %}">about</a>
35
      <a href="/{{ repo.name }}/" class="{% if active == "summary" %}active{% endif %}">summary</a>
36
      <a href="/{{ repo.name }}/refs/{{ query.id_param() }}" class="{% if active == "refs" %}active{% endif %}">refs</a>
37
      <a href="/{{ repo.name }}/log/{{ query.head_param() }}" class="{% if active == "log" %}active{% endif %}">log</a>
38
      <a href="/{{ repo.name }}/tree/{{ query.id_or_head_param() }}" class="{% if active == "tree" %}active{% endif %}">tree</a>
39
      <a href="/{{ repo.name }}/commit/{{ query.id_or_head_param() }}" class="{% if active == "commit" %}active{% endif %}">commit</a>
40
      <a href="/{{ repo.name }}/diff/{{ query.id_or_head_param() }}" class="{% if active == "diff" %}active{% endif %}">diff</a>
41
    </td>
42
    <td class="form">
43
      <form method="get" action="/{{ repo.name }}/log/">
44
        <select name="qt">
45
          <option value="msg" selected>msg</option>
46
          <option value="author">author</option>
47
          <option value="committer">committer</option>
48
        </select>
49
        <input type="search" name="v" size="10" value="">
50
        <input type="submit" value="search">
51
      </form>
52
    </td>
53
  </tr>
54
{% endmacro %}
55
56
{% macro diff_view(repo, diff, query) %}
57
  <table class="diffstat">
58
    <tbody>
59
      {% for file_diff in diff.file_diffs %}
60
        <tr>
61
          <td class="mode">{{ file_diff.mode }}</td>
62
          <td class="upd">
63
            <a href="/{{ repo.name }}/diff/{{ file_diff.path }}{% if let Some(id) = query.id %}?id={{ id }}{% endif %}" class="{{ file_diff.state }}">{{ file_diff.path }}</a>
64
          </td>
65
          <td class="right">{{ file_diff.total }}</td>
66
          <td class="graph">
67
            <table summary="file diffstat" style="width: {{ file_diff.total_percentage }}%">
68
              <tbody>
69
                <tr>
70
                  {% if file_diff.total != 0 %}
71
                    {% if file_diff.insertions_percentage > 0.0 %}
72
                      <td class="diffstat-addition" style="width: {{ file_diff.insertions_percentage }}%;"></td>
73
                    {% endif %}
74
                    {% if file_diff.deletions_percentage > 0.0 %}
75
                      <td class="diffstat-deletion" style="width: {{ file_diff.deletions_percentage }}%;"></td>
76
                    {% endif %}
77
                  {% endif %}
78
                </tr>
79
              </tbody>
80
            </table>
81
          </td>
82
        </tr>
83
      {% endfor %}
84
    </tbody>
85
  </table>
86
  <pre class="diff">{{ diff.stats }}
87
{{ diff.output|safe }}</pre>
88
{% endmacro %}
89
90
{% macro branches(branches, branches_has_more, has_prev, page, mode) %}
91
    <thead>
92
      <tr>
93
        <th>Branch</th>
94
        <th>Commit message</th>
95
        <th>Author</th>
96
        <th>Age</th>
97
      </tr>
98
    </thead>
99
    <tbody>
100
      {% for branch in branches %}
101
        <tr>
102
          <td>
103
            <a href="/{{ repo.name }}/log/?h={{ branch.name }}">{{ branch.name }}</a>
104
          </td>
105
          <td class="msg"><span class="msg-text">{{ branch.last_commit.summary()? }}</span></td>
106
          <td class="author">
107
            <span class="avatar">
108
              <img class="inline" src="{{ branch.author.avatar_url(20) }}" width="18" height="18" loading="lazy" decoding="async" alt="">
109
              <img class="onhover" src="{{ branch.author.avatar_url(128) }}" width="128" height="128" loading="lazy" decoding="async" alt="">
110
            </span>
111
            {{ branch.author.name }}
112
          </td>
113
          {% let time = branch.last_commit.committer.time.format_relative() %}
114
          <td class="{{ time.1 }}" data-sort="-{{ branch.last_commit.committer.time.seconds() }}" title="{{ branch.last_commit.committer.time.format() }}">{{ time.0 }}</td>
115
        </tr>
116
      {% endfor %}
117
    <tr class="no-background">
118
      {% if mode == "heads" %}
119
        <td colspan="4" class="pagination">
120
          {% if has_prev %}
121
            {% let offset = offset.saturating_sub(PAGE_SIZE) %}
122
            {% if offset > 0 %}
123
              <a href="/{{ repo.name }}/refs/heads/?ofs={{ offset }}">[prev]</a>
124
            {% else %}
125
              <a href="/{{ repo.name }}/refs/heads/">[prev]</a>
126
            {% endif %}
127
          {% endif %}
128
129
          {% if branches_has_more %}
130
            <a href="/{{ repo.name }}/refs/heads?ofs={{ offset.saturating_add(PAGE_SIZE) }}">[next]</a>
131
          {% endif %}
132
        </td>
133
      {% else if branches_has_more %}
134
        <td class="show_more">
135
          <a href="/{{ repo.name }}/refs/heads">[...]</a>
136
        </td>
137
      {% endif %}
138
    </tr>
139
  </tbody>
140
{% endmacro %}
141
142
{% macro tags(tags, tags_has_more, has_prev, page, mode) %}
143
    <thead>
144
      <tr>
145
        <th class="sort-desc" aria-sort="descending">Tag</th>
146
        <th>Download</th>
147
        <th>Author</th>
148
        <th>Age</th>
149
      </tr>
150
    </thead>
151
    <tbody>
152
      {% for tag in tags %}
153
        <tr>
154
          <td><a href="/{{ repo.name }}/tag/?h={{ tag.name }}">{{ tag.name }}</a></td>
155
          <td>
156
            <a href="/{{ repo.name }}/snapshot/?h={{ tag.name }}">{{ tag.name }}.tar.gz</a>
157
          </td>
158
          <td>
159
            {% if let Some(tagger) = tag.tagger %}
160
                <span class="avatar">
161
                  <img class="inline" src="{{ tagger.avatar_url(20) }}" width="18" height="18" loading="lazy" decoding="async" alt="">
162
                  <img class="onhover" src="{{ tagger.avatar_url(128) }}" width="128" height="128" loading="lazy" decoding="async" alt="">
163
                </span>
164
                {{ tagger.name }}
165
            {% endif %}
166
            </td>
167
            {% let time = tag.time.format_relative() %}
168
            <td class="{{ time.1 }}" data-sort="-{{ tag.time.seconds() }}" title="{{ tag.time.format() }}">{{ time.0 }}</td>
169
        </tr>
170
      {% endfor %}
171
      <tr class="no-background">
172
        {% if mode == "tags" %}
173
        <td colspan="4" class="pagination">
174
          {% if has_prev %}
175
            {% let offset = offset.saturating_sub(PAGE_SIZE) %}
176
            {% if offset > 0 %}
177
              <a href="/{{ repo.name }}/refs/tags/?ofs={{ offset }}">[prev]</a>
178
            {% else %}
179
              <a href="/{{ repo.name }}/refs/tags/">[prev]</a>
180
            {% endif %}
181
          {% endif %}
182
183
          {% if tags_has_more %}
184
            <a href="/{{ repo.name }}/refs/tags?ofs={{ offset.saturating_add(PAGE_SIZE) }}">[next]</a>
185
          {% endif %}
186
        </td>
187
        {% else if tags_has_more %}
188
        <td class="show_more">
189
          <a href="/{{ repo.name }}/refs/tags">[...]</a>
190
        </td>
191
        {% endif %}
192
      </tr>
193
  </tbody>
194
{% endmacro %}
195
196
{% macro commits(commits, commits_has_more, has_prev, page, mode) %}
197
    <thead>
198
      <tr>
199
        <th class="sort-asc" aria-sort="ascending">Age</th>
200
        <th>Commit message</th>
201
        <th>Author</th>
202
      </tr>
203
    </thead>
204
    <tbody>
205
      {% for commit in commits %}
206
        <tr>
207
          {% let time = commit.committer.time.format_relative() %}
208
          <td class="{{ time.1 }}" data-sort="-{{ commit.committer.time.seconds() }}" title="{{ commit.committer.time.format() }}">{{ time.0 }}</td>
209
          <td>
210
            <a href="/{{ repo.name }}/commit/?id={{ commit.id }}">{{ commit.summary()? | truncate(80)}}</a>
211
            {% if commit.is_head(repo)? %}<a href="/{{ repo.name }}/commit/?id={{ commit.id }}" class="badge_head">HEAD</a>{% endif %}
212
            {% for branch in commit.branch_tips(repo)? %}
213
            <a href="/{{ repo.name }}/log/?h={{ branch }}" class="badge_branch">{{ branch }}</a>
214
            {% endfor %}
215
          </td>
216
          <td>
217
            <span class="avatar">
218
              <img class="inline" src="{{ commit.author.avatar_url(20) }}" width="18" height="18" loading="lazy" decoding="async" alt="">
219
              <img class="onhover" src="{{ commit.author.avatar_url(128) }}" width="128" height="128" loading="lazy" decoding="async" alt="">
220
            </span>
221
            {{ commit.author.name }}
222
          </td>
223
        </tr>
224
      {% endfor %}
225
      <tr class="no-background">
226
      {% if mode == "log" %}
227
      <td colspan="3" class="pagination">
228
        {% if has_prev %}
229
          {% let offset = offset.saturating_sub(PAGE_SIZE) %}
230
          {% if offset > 0 %}
231
            <a href="/{{ repo.name }}/log/?ofs={{ offset }}">[prev]</a>
232
          {% else %}
233
            <a href="/{{ repo.name }}/log/">[prev]</a>
234
          {% endif %}
235
        {% endif %}
236
237
        {% if commits_has_more %}
238
        <a href="/{{ repo.name }}/log/?ofs={{ offset.saturating_add(PAGE_SIZE) }}">[next]</a>
239
        {% endif %}
240
      </td>
241
      {% else if commits_has_more %}
242
      <td class="show_more">
243
        <a href="/{{ repo.name }}/log/">[...]</a>
244
      </td>
245
      {% endif %}
246
      </tr>
247
    </tbody>
248
{% endmacro %}