Skip to content

Commit

Permalink
[CocoaPods] Added CocoaPods license and platform badges
Browse files Browse the repository at this point in the history
Using Orta-sanctioned colors from CocoaPods/pod-template#44
  • Loading branch information
segiddins authored and espadrine committed May 26, 2014
1 parent 64dabbb commit 8a12179
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,12 +778,14 @@ cache(function(data, match, sendBadge) {
}));

// CocoaPods version integration.
camp.route(/^\/cocoapods\/v\/(.*)\.(svg|png|gif|jpg)$/,
camp.route(/^\/cocoapods\/(v|p|l)\/(.*)\.(svg|png|gif|jpg)$/,
cache(function(data, match, sendBadge) {
var spec = match[1]; // eg, AFNetworking
var format = match[2];
var type = match[1];
var spec = match[2]; // eg, AFNetworking
var format = match[3];
var apiUrl = 'http://search.cocoapods.org/api/v1/pod/' + spec + '.json';
var badgeData = getBadgeData('pod', data);
badgeData.colorscheme = null;
request(apiUrl, function(err, res, buffer) {
if (err != null) {
badgeData.text[1] = 'inaccessible';
Expand All @@ -792,16 +794,25 @@ cache(function(data, match, sendBadge) {
try {
var data = JSON.parse(buffer);
var version = data.version;
var license = data.license;
var platforms = Object.keys(data.platforms).join(' | ');
version = version.replace(/^v/, "");
badgeData.text[1] = version;
if (/^\d/.test(badgeData.text[1])) {
badgeData.text[1] = 'v' + version;
}
if (version[0] === '0' || /dev/.test(version)) {
badgeData.colorscheme = 'orange';
} else {
badgeData.colorscheme = 'blue';
if (type === 'v') {
badgeData.text[1] = version;
if (/^\d/.test(badgeData.text[1])) {
badgeData.text[1] = 'v' + version;
}
badgeData.colorB = '#5BA7E9';
} else if (type === 'p') {
badgeData.text[0] = 'platform';
badgeData.text[1] = platforms;
badgeData.colorB = '#989898';
} else if (type === 'l') {
badgeData.text[0] = 'license';
badgeData.text[1] = license;
badgeData.colorB = '#373737';
}

sendBadge(format, badgeData);
} catch(e) {
badgeData.text[1] = 'invalid';
Expand Down

0 comments on commit 8a12179

Please sign in to comment.