From 554667bfdd323c79b75e835ac2edd3f371d8945f Mon Sep 17 00:00:00 2001 From: QriLa | Hyeon Gu <68494132+qyurila@users.noreply.github.com> Date: Tue, 11 Oct 2022 05:52:06 +0900 Subject: [PATCH] feat: Add `width` and `valign` attributes for cleaner (#344) --- .../__tests__/__snapshots__/index.js.snap | 74 +++++++++++++------ src/generate/__tests__/index.js | 15 ++++ src/generate/index.js | 14 +++- 3 files changed, 76 insertions(+), 27 deletions(-) diff --git a/src/generate/__tests__/__snapshots__/index.js.snap b/src/generate/__tests__/__snapshots__/index.js.snap index 3318357..b8f576a 100644 --- a/src/generate/__tests__/__snapshots__/index.js.snap +++ b/src/generate/__tests__/__snapshots__/index.js.snap @@ -13,9 +13,9 @@ These people contributed to the project: - - - + + +
Kent C. Dodds is awesome!Divjot Singh is awesome!Jeroen Engels is awesome!Kent C. Dodds is awesome!Divjot Singh is awesome!Jeroen Engels is awesome!
@@ -41,9 +41,9 @@ These people contributed to the project: - - - + + + @@ -78,9 +78,9 @@ These people contributed to the project:
Kent C. Dodds is awesome!Divjot Singh is awesome!Jeroen Engels is awesome!Kent C. Dodds is awesome!Divjot Singh is awesome!Jeroen Engels is awesome!
- - - + + +
Kent C. Dodds is awesome!Divjot Singh is awesome!Jeroen Engels is awesome!Kent C. Dodds is awesome!Divjot Singh is awesome!Jeroen Engels is awesome!
@@ -106,15 +106,15 @@ These people contributed to the project: - - - - - + + + + + - - + +
Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!
Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!
@@ -140,15 +140,15 @@ These people contributed to the project: - - - - - + + + + + - - + + @@ -169,3 +169,31 @@ These people contributed to the project: Thanks a lot everyone!" `; + +exports[`validate if cell width attribute is floored correctly 1`] = ` +"# project + +Description + +## Contributors +These people contributed to the project: + + + +
Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!
Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!
+ + + + + + + +
Kent C. Dodds is awesome!Kent C. Dodds is awesome!Kent C. Dodds is awesome!
+ + + + + + +Thanks a lot everyone!" +`; diff --git a/src/generate/__tests__/index.js b/src/generate/__tests__/index.js index 524e58b..eeb285c 100644 --- a/src/generate/__tests__/index.js +++ b/src/generate/__tests__/index.js @@ -238,3 +238,18 @@ test('replace all-contributors badge if present', () => { expect(result).toBe(expected) }) + +test('validate if cell width attribute is floored correctly', () => { + const {kentcdodds} = contributors + const {options, content} = fixtures() + const contributorList = [ + kentcdodds, + kentcdodds, + kentcdodds, + ] + + options.contributorsPerLine = 7 + const result = generate(options, contributorList, content) + + expect(result).toMatchSnapshot() +}) diff --git a/src/generate/index.js b/src/generate/index.js index 78de5e3..11eaedb 100644 --- a/src/generate/index.js +++ b/src/generate/index.js @@ -1,4 +1,5 @@ const _ = require('lodash/fp') +const floor = require('lodash/floor') const formatBadge = require('./format-badge') const formatContributor = require('./format-contributor') @@ -43,9 +44,12 @@ function injectListBetweenTags(newContent) { } } -function formatLine(contributors) { - return `${contributors.join( - '\n ', +function formatLine(options, contributors) { + const width = floor(_.divide(100)(options.contributorsPerLine), 2) + const attributes = `align="center" valign="top" width="${width}%"` + + return `${contributors.join( + `\n `, )}` } @@ -74,7 +78,9 @@ function generateContributorsList(options, contributors) { return formatContributor(options, contributor) }), _.chunk(options.contributorsPerLine), - _.map(formatLine), + _.map((currentLineContributors) => formatLine( + options, currentLineContributors + )), _.join('\n \n \n '), newContent => { if (options.linkToUsage) {