Skip to content

Commit 2c07af8

Browse files
authoredApr 26, 2023
feat: add wrapperTemplate option (#348)
1 parent 96534ec commit 2c07af8

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed
 

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

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`replace the content between the ALL-CONTRIBUTORS-LIST tags by a custom wrapper around the list of contributors contained in the "bodyContent" tag 1`] = `
4+
"# project
5+
6+
Description
7+
8+
## Contributors
9+
These people contributed to the project:
10+
<!-- ALL-CONTRIBUTORS-LIST:START -->
11+
<!-- prettier-ignore-start -->
12+
<!-- markdownlint-disable -->
13+
<p>
14+
<tr>
15+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Kent C. Dodds is awesome!</td>
16+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Divjot Singh is awesome!</td>
17+
<td align=\\"center\\" valign=\\"top\\" width=\\"20%\\">Jeroen Engels is awesome!</td>
18+
</tr>
19+
</p>
20+
21+
<!-- markdownlint-restore -->
22+
<!-- prettier-ignore-end -->
23+
24+
<!-- ALL-CONTRIBUTORS-LIST:END -->
25+
26+
Thanks a lot everyone!"
27+
`;
28+
329
exports[`replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors 1`] = `
430
"# project
531

‎src/generate/__tests__/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of c
6969
expect(result).toMatchSnapshot()
7070
})
7171

72+
test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a custom wrapper around the list of contributors contained in the "bodyContent" tag', () => {
73+
const {kentcdodds, bogas04} = contributors
74+
const {options, jfmengels, content} = fixtures()
75+
const contributorList = [kentcdodds, bogas04, jfmengels]
76+
const result = generate(
77+
Object.assign(options, { wrapperTemplate: '<p><%= bodyContent %></p>'}),
78+
contributorList,
79+
content,
80+
)
81+
82+
expect(result).toMatchSnapshot()
83+
})
84+
7285
test('split contributors into multiples lines when there are too many', () => {
7386
const {kentcdodds} = contributors
7487
const {options, content} = fixtures()

‎src/generate/index.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ function formatFooter(options) {
6666

6767
function generateContributorsList(options, contributors) {
6868
const tableFooter = formatFooter(options)
69+
const defaultWrapperTemplate = _.template('\n<table>\n <tbody><%= bodyContent %> </tbody>\n<%= tableFooterContent %></table>\n\n')
70+
const wrapperTemplate = options.wrapperTemplate ? _.template(`\n${options.wrapperTemplate}\n\n`) : defaultWrapperTemplate
71+
const seperator = options.wrapperTemplate ? '\n </tr><br />\n <tr>\n ' : '\n </tr>\n <tr>\n '
72+
6973
let tableFooterContent = ''
7074

7175
return _.flow(
@@ -81,12 +85,15 @@ function generateContributorsList(options, contributors) {
8185
_.map((currentLineContributors) => formatLine(
8286
options, currentLineContributors
8387
)),
84-
_.join('\n </tr>\n <tr>\n '),
88+
_.join(seperator),
8589
newContent => {
8690
if (options.linkToUsage) {
8791
tableFooterContent = ` <tfoot>\n ${tableFooter}\n </tfoot>\n`
8892
}
89-
return `\n<table>\n <tbody>\n <tr>\n ${newContent}\n </tr>\n </tbody>\n${tableFooterContent}</table>\n\n`
93+
94+
const bodyContent = `\n <tr>\n ${newContent}\n </tr>\n`
95+
96+
return wrapperTemplate({ bodyContent, tableFooterContent})
9097
},
9198
)(contributors)
9299
}
@@ -135,6 +142,7 @@ module.exports = function generate(options, contributors, fileContent) {
135142
? '\n'
136143
: generateContributorsList(options, contributors)
137144
const badge = formatBadge(options, contributors)
145+
138146
return _.flow(
139147
injectListBetweenTags(contributorsList),
140148
replaceBadge(badge),

0 commit comments

Comments
 (0)
Please sign in to comment.