forked from kat4/commit4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
partials.js
55 lines (36 loc) · 1.67 KB
/
partials.js
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
function renderHTML(commitHistory) {
var Partials = {
header: '<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><link rel="stylesheet" href="/css/commits.css"></head><body><h1></h1>',
commitContainerOpen: '<div id="commits-container">',
commit: '',
commitContainerClose: '</div>',
scripts: '<script type="text/javascript" src="/js/commit4.js"></script>',
footer: '</body></html>'
};
Object.keys(commitHistory).forEach(function(key) {
var commitFiles = '';
commitHistory[key].files.forEach(function(file) {
var percentAdded = file.additions / file.changes * 100;
var percentDeleted = file.deletions / file.changes * 100;
commitFiles += '<div class="file circle" data-filename="' + file.filename + '" data-changes="' + file.changes + '" data-added="' + file.additions + '" data-deleted="' + file.deletions + '"><div class="file-stats"><div class="added" style="height:' + percentAdded + '%;">' +
file.additions +
'</div><div class="deleted" style="height:' + percentDeleted + '%;">' +
file.deletions +
'</div></div></div>'
});
Partials.commit += '<div class="commit" data-sha="' +
commitHistory[key] +
'">'+
'<div class="avatar circle" style="background-image:url(\'' +
commitHistory[key].author.avatar +
'\')" data-author="' +
commitHistory[key].author.username +
'"></div>' +
commitFiles +
'</div>';
});
var commitHistoryHTML = Partials.header + Partials.commitContainerOpen +
Partials.commit + Partials.commitContainerClose + Partials.scripts + Partials.footer;
return commitHistoryHTML;
}
module.exports = renderHTML;