Skip to content

Commit 0be7a63

Browse files
authoredOct 6, 2022
fix: cleanup table footer (#341)
1 parent 8fc7c7e commit 0be7a63

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed
 

‎src/generate/__tests__/__snapshots__/index.js.snap

+28-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ These people contributed to the project:
1818
<td align=\\"center\\">Jeroen Engels is awesome!</td>
1919
</tr>
2020
</tbody>
21-
<tfoot>
22-
23-
</tfoot>
2421
</table>
2522
2623
<!-- markdownlint-restore -->
@@ -68,6 +65,34 @@ These people contributed to the project:
6865
Thanks a lot everyone!"
6966
`;
7067
68+
exports[`replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors without linkToUsage 1`] = `
69+
"# project
70+
71+
Description
72+
73+
## Contributors
74+
These people contributed to the project:
75+
<!-- ALL-CONTRIBUTORS-LIST:START -->
76+
<!-- prettier-ignore-start -->
77+
<!-- markdownlint-disable -->
78+
<table>
79+
<tbody>
80+
<tr>
81+
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
82+
<td align=\\"center\\">Divjot Singh is awesome!</td>
83+
<td align=\\"center\\">Jeroen Engels is awesome!</td>
84+
</tr>
85+
</tbody>
86+
</table>
87+
88+
<!-- markdownlint-restore -->
89+
<!-- prettier-ignore-end -->
90+
91+
<!-- ALL-CONTRIBUTORS-LIST:END -->
92+
93+
Thanks a lot everyone!"
94+
`;
95+
7196
exports[`split contributors into multiples lines when there are too many 1`] = `
7297
"# project
7398
@@ -92,9 +117,6 @@ These people contributed to the project:
92117
<td align=\\"center\\">Kent C. Dodds is awesome!</td>
93118
</tr>
94119
</tbody>
95-
<tfoot>
96-
97-
</tfoot>
98120
</table>
99121
100122
<!-- markdownlint-restore -->

‎src/generate/__tests__/index.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,24 @@ test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of c
4747
const {kentcdodds, bogas04} = contributors
4848
const {options, jfmengels, content} = fixtures()
4949
const contributorList = [kentcdodds, bogas04, jfmengels]
50-
const result = generate(Object.assign(options, { linkToUsage: true }), contributorList, content)
50+
const result = generate(
51+
Object.assign(options, {linkToUsage: true}),
52+
contributorList,
53+
content,
54+
)
55+
56+
expect(result).toMatchSnapshot()
57+
})
58+
59+
test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors without linkToUsage', () => {
60+
const {kentcdodds, bogas04} = contributors
61+
const {options, jfmengels, content} = fixtures()
62+
const contributorList = [kentcdodds, bogas04, jfmengels]
63+
const result = generate(
64+
Object.assign(options, {linkToUsage: false}),
65+
contributorList,
66+
content,
67+
)
5168

5269
expect(result).toMatchSnapshot()
5370
})
@@ -81,7 +98,11 @@ test('split contributors into multiples lines when there are too many with linkT
8198
kentcdodds,
8299
kentcdodds,
83100
]
84-
const result = generate(Object.assign(options, { linkToUsage: true }), contributorList, content)
101+
const result = generate(
102+
Object.assign(options, {linkToUsage: true}),
103+
contributorList,
104+
content,
105+
)
85106

86107
expect(result).toMatchSnapshot()
87108
})

‎src/generate/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function formatFooter(options) {
6262

6363
function generateContributorsList(options, contributors) {
6464
const tableFooter = formatFooter(options)
65+
let tableFooterContent = ''
6566

6667
return _.flow(
6768
_.sortBy(contributor => {
@@ -76,7 +77,10 @@ function generateContributorsList(options, contributors) {
7677
_.map(formatLine),
7778
_.join('\n </tr>\n <tr>\n '),
7879
newContent => {
79-
return `\n<table>\n <tbody>\n <tr>\n ${newContent}\n </tr>\n </tbody>\n <tfoot>\n ${tableFooter}\n </tfoot>\n</table>\n\n`
80+
if (options.linkToUsage) {
81+
tableFooterContent = ` <tfoot>\n ${tableFooter}\n </tfoot>\n`
82+
}
83+
return `\n<table>\n <tbody>\n <tr>\n ${newContent}\n </tr>\n </tbody>\n${tableFooterContent}</table>\n\n`
8084
},
8185
)(contributors)
8286
}

0 commit comments

Comments
 (0)
Please sign in to comment.