From dafef7536a06c9624a205dbe18f819a9f1ab433b Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Sun, 20 Mar 2016 20:33:01 +0100 Subject: [PATCH] Fix image size not having a default value --- .all-contributorsrc | 3 +-- README.md | 2 +- lib/generate/formatContributor.js | 5 ++++- lib/generate/formatContributor.test.js | 21 ++++++++++++++++----- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 0b94bd8..9b4c5fd 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1,7 +1,6 @@ { "projectOwner": "jfmengels" , "projectName": "all-contributors-cli" -, "imageSize": 100 , "contributors": [ { "login": "jfmengels" @@ -24,4 +23,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/README.md b/README.md index b9822a9..8505bb5 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ Where: Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): -| [![Jeroen Engels](https://avatars.githubusercontent.com/u/3869412?v=3&s=100)
Jeroen Engels](https://github.com/jfmengels)
[💻](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)
Kent C. Dodds](http://kentcdodds.com/)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds) | +| [![Jeroen Engels](https://avatars.githubusercontent.com/u/3869412?v=3&s=undefined)
Jeroen Engels](https://github.com/jfmengels)
[💻](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)
Kent C. Dodds](http://kentcdodds.com/)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds) | | :---: | :---: | diff --git a/lib/generate/formatContributor.js b/lib/generate/formatContributor.js index 469c549..cc8b72a 100644 --- a/lib/generate/formatContributor.js +++ b/lib/generate/formatContributor.js @@ -8,6 +8,8 @@ var avatarTemplate = _.template('![<%= contributor.name %>](<%= contributor.avat var avatarBlockTemplate = _.template('[<%= avatar %>
<%= contributor.name %>](<%= contributor.profile %>)'); var contributorTemplate = _.template('<%= avatarBlock %>
<%= 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 }); } diff --git a/lib/generate/formatContributor.test.js b/lib/generate/formatContributor.test.js index 04c61b0..b4bdc39 100644 --- a/lib/generate/formatContributor.test.js +++ b/lib/generate/formatContributor.test.js @@ -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)
Kent C. Dodds](http://kentcdodds.com)
👀'; + const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=150)
Kent C. Dodds](http://kentcdodds.com)
👀'; 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)
Kent C. Dodds](http://kentcdodds.com)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=kentcdodds) 👀 ❓'; + const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=150)
Kent C. Dodds](http://kentcdodds.com)
[📖](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' ); });