-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
42 lines (33 loc) · 1.22 KB
/
index.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
// Duplicated then adapted from badges/shields
var fs = require('fs');
var path = require('path');
var dot = require('dot');
var colorscheme = require('./colorscheme');
dot.templateSettings.strip = false; // Do not strip whitespaces.
// cache templates.
var templates = {};
var templateFiles = fs.readdirSync(path.join(__dirname, 'templates'));
templateFiles.forEach(function(filename) {
var templateData = fs.readFileSync(path.join(__dirname, 'templates', filename)).toString();
templates[filename.split('.')[0]] = dot.template(templateData);
});
function escapeXml(s) {
return s.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
exports.svg = function(subject, status, color, style) {
var template = templates[style] || templates.plastic;
var data = {
subject: '' + subject,
status: '' + status,
colors: colorscheme[color] || colorscheme.red,
escapeXml: escapeXml
};
// less clean way to calculate string length thant the original shields programm.
// But prevents building and loading C++ addon 'canvas'.
data.widths = [(data.subject.length * 6) + 10, (data.status.length * 6) + 10];
return template(data);
};