Load all templates through dot.
This commit is contained in:
parent
d578b65513
commit
2343e24d8a
21
badge.js
21
badge.js
|
@ -18,31 +18,22 @@ canvasContext.font = '11px Verdana, "DejaVu Sans"';
|
|||
// cache templates.
|
||||
var templates = {};
|
||||
var templateFiles = fs.readdirSync('templates');
|
||||
templateFiles.forEach(function(file) {
|
||||
templates[file] = fs.readFileSync(
|
||||
path.join(__dirname, 'templates', file)).toString();
|
||||
templateFiles.forEach(function(filename) {
|
||||
var templateData = fs.readFileSync(
|
||||
path.join(__dirname, 'templates', filename)).toString();
|
||||
var style = filename.slice(0, -('-template.svg'.length));
|
||||
templates[style] = dot.template(templateData);
|
||||
});
|
||||
|
||||
var colorscheme = require(path.join(__dirname, 'colorscheme.json'));
|
||||
|
||||
function makeTemplate(template) {
|
||||
// Template crafting action below.
|
||||
var template = templates[(template || 'default') + '-template.svg'];
|
||||
return dot.template(template);
|
||||
}
|
||||
|
||||
var defaultTemplate = makeTemplate();
|
||||
|
||||
function optimize(string, callback) {
|
||||
var svgo = new SVGO();
|
||||
svgo.optimize(string, callback);
|
||||
}
|
||||
|
||||
function makeImage(data, cb) {
|
||||
var template = defaultTemplate;
|
||||
if (data.template) {
|
||||
template = makeTemplate(data.template);
|
||||
}
|
||||
var template = templates[data.template || 'default'];
|
||||
if (data.colorscheme) {
|
||||
data.colorA = colorscheme[data.colorscheme].colorA;
|
||||
data.colorB = colorscheme[data.colorscheme].colorB;
|
||||
|
|
|
@ -1 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="110" height="18"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-opacity=".3"/><stop offset="1" stop-opacity=".5"/></linearGradient><rect rx="4" width="110" height="18" fill="#555"/><rect rx="4" x="63" width="47" height="18" fill="#a4a61d"/><path fill="#a4a61d" d="M63 0h4v18h-4z"/><rect rx="4" width="110" height="18" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="32.5" y="13" fill="#010101" fill-opacity=".3">coverage</text><text x="32.5" y="12">coverage</text><text x="85.5" y="13" fill="#010101" fill-opacity=".3">82.3%</text><text x="85.5" y="12">82.3%</text></g></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="110" height="18"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-opacity=".3"/><stop offset="1" stop-opacity=".5"/></linearGradient><rect rx="4" width="110" height="18" fill="#555"/><rect rx="4" x="63" width="47" height="18" fill="#a4a61d"/><path fill="#a4a61d" d="M63 0h4v18h-4z"/><rect rx="4" width="110" height="18" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="32.5" y="13" fill="#010101" fill-opacity=".3">coverage</text><text x="32.5" y="12">coverage</text><text x="85.5" y="13" fill="#010101" fill-opacity=".3">81.4%</text><text x="85.5" y="12">81.4%</text></g></svg>
|
Before Width: | Height: | Size: 827 B After Width: | Height: | Size: 827 B |
Loading…
Reference in New Issue
Block a user