Skip to content

Commit

Permalink
feat: Add width and valign attributes for cleaner <td> (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
qyurila authored Oct 10, 2022
1 parent fb8f89f commit 554667b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 27 deletions.
74 changes: 51 additions & 23 deletions src/generate/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ These people contributed to the project:
<table>
<tbody>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Divjot Singh is awesome!</td>
<td align=\\"center\\">Jeroen Engels is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Divjot Singh is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Jeroen Engels is awesome!</td>
</tr>
</tbody>
</table>
Expand All @@ -41,9 +41,9 @@ These people contributed to the project:
<table>
<tbody>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Divjot Singh is awesome!</td>
<td align=\\"center\\">Jeroen Engels is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Divjot Singh is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Jeroen Engels is awesome!</td>
</tr>
</tbody>
<tfoot>
Expand Down Expand Up @@ -78,9 +78,9 @@ These people contributed to the project:
<table>
<tbody>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Divjot Singh is awesome!</td>
<td align=\\"center\\">Jeroen Engels is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Divjot Singh is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Jeroen Engels is awesome!</td>
</tr>
</tbody>
</table>
Expand All @@ -106,15 +106,15 @@ These people contributed to the project:
<table>
<tbody>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
</tr>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
</tr>
</tbody>
</table>
Expand All @@ -140,15 +140,15 @@ These people contributed to the project:
<table>
<tbody>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
</tr>
<tr>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
</tr>
</tbody>
<tfoot>
Expand All @@ -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:
<!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tbody>
<tr>
<td align=\\"center\\" valign=\\"top\\" width=\\"14.28%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"14.28%\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\" valign=\\"top\\" width=\\"14.28%\\">Kent C. Dodds is awesome!</td>
</tr>
</tbody>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
Thanks a lot everyone!"
`;
15 changes: 15 additions & 0 deletions src/generate/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
14 changes: 10 additions & 4 deletions src/generate/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const _ = require('lodash/fp')
const floor = require('lodash/floor')
const formatBadge = require('./format-badge')
const formatContributor = require('./format-contributor')

Expand Down Expand Up @@ -43,9 +44,12 @@ function injectListBetweenTags(newContent) {
}
}

function formatLine(contributors) {
return `<td align="center">${contributors.join(
'</td>\n <td align="center">',
function formatLine(options, contributors) {
const width = floor(_.divide(100)(options.contributorsPerLine), 2)
const attributes = `align="center" valign="top" width="${width}%"`

return `<td ${attributes}>${contributors.join(
`</td>\n <td ${attributes}>`,
)}</td>`
}

Expand Down Expand Up @@ -74,7 +78,9 @@ function generateContributorsList(options, contributors) {
return formatContributor(options, contributor)
}),
_.chunk(options.contributorsPerLine),
_.map(formatLine),
_.map((currentLineContributors) => formatLine(
options, currentLineContributors
)),
_.join('\n </tr>\n <tr>\n '),
newContent => {
if (options.linkToUsage) {
Expand Down

0 comments on commit 554667b

Please sign in to comment.