Fix image size not having a default value

This commit is contained in:
Jeroen Engels 2016-03-20 20:33:01 +01:00
parent f75d8541c8
commit dafef7536a
4 changed files with 22 additions and 9 deletions

View file

@ -1,7 +1,6 @@
{
"projectOwner": "jfmengels"
, "projectName": "all-contributors-cli"
, "imageSize": 100
, "contributors": [
{
"login": "jfmengels"
@ -24,4 +23,4 @@
]
}
]
}
}

View file

@ -108,7 +108,7 @@ Where:
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [![Jeroen Engels](https://avatars.githubusercontent.com/u/3869412?v=3&s=100)<br /><sub>Jeroen Engels</sub>](https://github.com/jfmengels)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=jfmengels) [📖](https://github.com/jfmengels/all-contributors-cli/commits?author=jfmengels) [⚠️](https://github.com/jfmengels/all-contributors-cli/commits?author=jfmengels) | [![Kent C. Dodds](https://avatars.githubusercontent.com/u/1500684?v=3&s=100)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com/)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds) |
| [![Jeroen Engels](https://avatars.githubusercontent.com/u/3869412?v=3&s=undefined)<br /><sub>Jeroen Engels</sub>](https://github.com/jfmengels)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=jfmengels) [📖](https://github.com/jfmengels/all-contributors-cli/commits?author=jfmengels) [⚠️](https://github.com/jfmengels/all-contributors-cli/commits?author=jfmengels) | [![Kent C. Dodds](https://avatars.githubusercontent.com/u/1500684?v=3&s=undefined)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com/)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds) |
| :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->

View file

@ -8,6 +8,8 @@ var avatarTemplate = _.template('![<%= contributor.name %>](<%= contributor.avat
var avatarBlockTemplate = _.template('[<%= avatar %><br /><sub><%= contributor.name %></sub>](<%= contributor.profile %>)');
var contributorTemplate = _.template('<%= avatarBlock %><br /><%= contributions %>');
var defaultImageSize = 100;
function defaultTemplate(templateData) {
var avatar = avatarTemplate(templateData);
var avatarBlock = avatarBlockTemplate(_.assign({avatar: avatar}, templateData));
@ -17,8 +19,9 @@ function defaultTemplate(templateData) {
function updateAvatarUrl(options, contributor) {
var avatarUrl = contributor.avatar_url;
var paramJoiner = _.includes('?', avatarUrl) ? '&' : '?';
var imageSize = options.imageSize || defaultImageSize;
return _.assign(contributor, {
avatar_url: avatarUrl + paramJoiner + 's=' + options.imageSize
avatar_url: avatarUrl + paramJoiner + 's=' + imageSize
});
}

View file

@ -7,7 +7,7 @@ function fixtures() {
const options = {
projectOwner: 'jfmengels',
projectName: 'all-contributors-cli',
imageSize: 100
imageSize: 150
};
return {options};
}
@ -16,7 +16,7 @@ test('should format a simple contributor', t => {
const contributor = _.assign(contributors.kentcdodds, {contributions: ['review']});
const {options} = fixtures();
const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=100)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com)<br />👀';
const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=150)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com)<br />👀';
t.is(formatContributor(options, contributor), expected);
});
@ -25,7 +25,7 @@ test('should format contributor with complex contribution types', t => {
const contributor = contributors.kentcdodds;
const {options} = fixtures();
const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=100)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds) 👀 ❓';
const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=150)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds) 👀 ❓';
t.is(formatContributor(options, contributor), expected);
});
@ -53,9 +53,20 @@ test('should add image size to url', t => {
});
t.is(formatContributor(options, contributionWithoutQuestionMarkUrl),
'Kent C. Dodds at www.some-url-without-question-mark.com?s=100'
'Kent C. Dodds at www.some-url-without-question-mark.com?s=150'
);
t.is(formatContributor(options, contributionWithQuestionMarkUrl),
'Kent C. Dodds at www.some-url-with-question-mark.com?v=3&s=100'
'Kent C. Dodds at www.some-url-with-question-mark.com?v=3&s=150'
);
});
test('should default image size to 100', t => {
const {options} = fixtures();
const contributor = contributors.kentcdodds;
options.contributorTemplate = '<%= contributor.name %> at <%= contributor.avatar_url %>';
delete options.imageSize;
t.is(formatContributor(options, contributor),
'Kent C. Dodds at https://avatars1.githubusercontent.com/u/1500684?s=100'
);
});