2016-03-01 22:30:14 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _ = require('lodash/fp');
|
|
|
|
var formatContributionType = require('./formatContributionType');
|
|
|
|
|
|
|
|
var avatarTemplate = _.template('![<%= contributor.name %>](<%= contributor.avatar_url %>)');
|
2016-03-06 18:37:26 +00:00
|
|
|
var avatarBlockTemplate = _.template('[<%= avatar %><br /><sub><%= contributor.name %></sub>](<%= contributor.profile %>)');
|
2016-03-01 22:30:14 +00:00
|
|
|
var contributorTemplate = _.template('<%= avatarBlock %><br /><%= contributions %>');
|
|
|
|
|
2016-03-20 19:33:01 +00:00
|
|
|
var defaultImageSize = 100;
|
|
|
|
|
2016-03-01 22:30:14 +00:00
|
|
|
function defaultTemplate(templateData) {
|
|
|
|
var avatar = avatarTemplate(templateData);
|
2016-03-06 23:20:24 +00:00
|
|
|
var avatarBlock = avatarBlockTemplate(_.assign({avatar: avatar}, templateData));
|
|
|
|
return contributorTemplate(_.assign({avatarBlock: avatarBlock}, templateData));
|
2016-03-01 22:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateAvatarUrl(options, contributor) {
|
|
|
|
var avatarUrl = contributor.avatar_url;
|
|
|
|
var paramJoiner = _.includes('?', avatarUrl) ? '&' : '?';
|
2016-03-20 19:33:01 +00:00
|
|
|
var imageSize = options.imageSize || defaultImageSize;
|
2016-03-01 22:30:14 +00:00
|
|
|
return _.assign(contributor, {
|
2016-03-20 19:33:01 +00:00
|
|
|
avatar_url: avatarUrl + paramJoiner + 's=' + imageSize
|
2016-03-01 22:30:14 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function formatContributor(options, contributor) {
|
2016-03-06 15:49:46 +00:00
|
|
|
var formatter = _.partial(formatContributionType, [options, contributor]);
|
|
|
|
var contributions = contributor.contributions
|
|
|
|
.map(formatter)
|
|
|
|
.join(' ');
|
2016-03-01 22:30:14 +00:00
|
|
|
var templateData = {
|
|
|
|
contributions: contributions,
|
|
|
|
contributor: updateAvatarUrl(options, contributor),
|
|
|
|
options: options
|
|
|
|
};
|
2016-03-06 15:49:46 +00:00
|
|
|
var customTemplate = options.contributorTemplate && _.template(options.contributorTemplate);
|
2016-03-01 22:30:14 +00:00
|
|
|
return (customTemplate || defaultTemplate)(templateData);
|
|
|
|
};
|