forked from yuki-kimoto/gitprep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blame.html.ep
145 lines (129 loc) · 4.61 KB
/
blame.html.ep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<%
# API
my $api = gitprep_api;
# Git
my $git = $self->app->git;
# Parameters
my $user_id = param('user');
my $project_id = param('project');
my $rev_file = param('rev_file');
my $is_wiki = (stash('tab') // '') eq 'wiki';
my $user_project_path = "/$user_id/$project_id";
if ($is_wiki) {
$user_project_path .= '/wiki';
}
my $rep_info = $is_wiki ? app->wiki_rep_info($user_id, $project_id) : app->rep_info($user_id, $project_id);
my ($rev, $file) = $git->parse_rev_path($rep_info, $rev_file);
# Commit
my $commit = $git->last_change_commit($rep_info, $rev, $file);
# Authors
my $authors = $git->authors($rep_info, $rev, $file);
# File size
my $file_size = $git->blob_size($rep_info, $rev, $file);
# File mode
my $mode = $git->blob_mode($rep_info, $rev, $file);
my $file_type = $git->file_type_long($mode);
# MIME type
my $mime_type = $git->blob_mime_type($rep_info, $rev, $file);
# Blame
my $blame = $git->blame($rep_info, $rev, $file);
my $blame_lines = $blame->{lines};
my $blame_min_author_time = $blame->{min_author_time};
my $blame_max_author_time = $blame->{max_author_time};
# Color
my $colors = [
'#ffeca7',
'#ffdd8c',
'#ffdd7c',
'#fba447',
'#f68736',
'#f37636',
'#ca6632',
'#c0513f',
'#a2503a',
'#793738'
];
# Variables for included template
stash(id => $rev, project => $project_id, rev => $rev);
%>
% layout 'common' , title => "$user_id/$project_id at $rev";
%= include '/include/header';
<!-- Blame page -->
<div class="container">
<div class="blame-page-path">
%= include '/include/page_path', Path => $file;
<div class="blame-gradation">
Newer
% for my $color (@$colors) {
<span style="font-size:20px;color:<%= $color %>">■</span>
% }
Older
</div>
</div>
<div class="file-header">
<div class="file-header-left">
<i class="icon-file icon-white"></i>
<%= @$blame_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_path/raw/$rev/$file") %>">Raw</a>
</li>
<li>
<a class="btn btn-small" href="<%= url_for("$user_project_path/blob/$rev/$file") %>">Normal View</a>
</li>
<li>
<a class="btn btn-small" href="<%= url_for("$user_project_path/commits/$rev/$file") %>">History</a>
</li>
</ul>
</div>
</div>
<div class="blame-body-container">
<table class="blame-body">
% for my $line (@$blame_lines) {
<%
my $blame_commit = $line->{commit};
my $summary = $line->{summary};
my $summary_short= length $summary > 28 ? substr($summary, 0, 28) . '...' : $summary;
my $time_rate = $blame_max_author_time == $blame_min_author_time
? 1
: ($blame_max_author_time - $line->{author_time}) / ($blame_max_author_time - $blame_min_author_time);
my $color_number = int($time_rate * 10);
$color_number = 9 if $color_number == 10;
my $hot_color = $colors->[$color_number];
%>
<tr id="L<%= $line->{number} %>">
% if ($line->{before_same_commit}) {
<td class="blame-body-left" nowrap style="border-right:2px solid <%= $hot_color %>"></td>
% } else {
<td class="blame-body-left" nowrap style="border-right:2px solid <%= $hot_color %>">
<div class="blame-summary-container">
<div class="blame-summary">
<%= $summary_short %>
</div>
<div class="blame-commit-id">
<a href="<%= url_for("$user_project_path/commit/$blame_commit") %>" ><%= substr($blame_commit, 0, 7) %></a>
</div>
</div>
<div class="blame-author">
<span title="<%= $line->{author_email} %>"><%= $line->{author} %></span>
authored on
<%= $line->{author_age_string_date_local} %>
</div>
</td>
% }
<td class="blame-body-center" nowrap>
<%= $line->{number} %>
</td>
<td nowrap class="blame-body-right">
<pre style="border:none;background:white;margin:0;padding:0;white-space: nowrap;"><%= $line->{content} %></pre>
</td>
</tr>
% }
</table>
</div>
</div>
%= include '/include/footer';