Skip to content

Commit

Permalink
fix: cleanup table footer (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
tenshiAMD authored Oct 6, 2022
1 parent 8fc7c7e commit 0be7a63
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
34 changes: 28 additions & 6 deletions src/generate/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ These people contributed to the project:
<td align=\\"center\\">Jeroen Engels is awesome!</td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
<!-- markdownlint-restore -->
Expand Down Expand Up @@ -68,6 +65,34 @@ These people contributed to the project:
Thanks a lot everyone!"
`;
exports[`replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors without linkToUsage 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\\">Kent C. Dodds is awesome!</td>
<td align=\\"center\\">Divjot Singh is awesome!</td>
<td align=\\"center\\">Jeroen Engels is awesome!</td>
</tr>
</tbody>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
Thanks a lot everyone!"
`;
exports[`split contributors into multiples lines when there are too many 1`] = `
"# project
Expand All @@ -92,9 +117,6 @@ These people contributed to the project:
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
<!-- markdownlint-restore -->
Expand Down
25 changes: 23 additions & 2 deletions src/generate/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,24 @@ test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of c
const {kentcdodds, bogas04} = contributors
const {options, jfmengels, content} = fixtures()
const contributorList = [kentcdodds, bogas04, jfmengels]
const result = generate(Object.assign(options, { linkToUsage: true }), contributorList, content)
const result = generate(
Object.assign(options, {linkToUsage: true}),
contributorList,
content,
)

expect(result).toMatchSnapshot()
})

test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors without linkToUsage', () => {
const {kentcdodds, bogas04} = contributors
const {options, jfmengels, content} = fixtures()
const contributorList = [kentcdodds, bogas04, jfmengels]
const result = generate(
Object.assign(options, {linkToUsage: false}),
contributorList,
content,
)

expect(result).toMatchSnapshot()
})
Expand Down Expand Up @@ -81,7 +98,11 @@ test('split contributors into multiples lines when there are too many with linkT
kentcdodds,
kentcdodds,
]
const result = generate(Object.assign(options, { linkToUsage: true }), contributorList, content)
const result = generate(
Object.assign(options, {linkToUsage: true}),
contributorList,
content,
)

expect(result).toMatchSnapshot()
})
Expand Down
6 changes: 5 additions & 1 deletion src/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function formatFooter(options) {

function generateContributorsList(options, contributors) {
const tableFooter = formatFooter(options)
let tableFooterContent = ''

return _.flow(
_.sortBy(contributor => {
Expand All @@ -76,7 +77,10 @@ function generateContributorsList(options, contributors) {
_.map(formatLine),
_.join('\n </tr>\n <tr>\n '),
newContent => {
return `\n<table>\n <tbody>\n <tr>\n ${newContent}\n </tr>\n </tbody>\n <tfoot>\n ${tableFooter}\n </tfoot>\n</table>\n\n`
if (options.linkToUsage) {
tableFooterContent = ` <tfoot>\n ${tableFooter}\n </tfoot>\n`
}
return `\n<table>\n <tbody>\n <tr>\n ${newContent}\n </tr>\n </tbody>\n${tableFooterContent}</table>\n\n`
},
)(contributors)
}
Expand Down

0 comments on commit 0be7a63

Please sign in to comment.