mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 13:36:29 +00:00
feat: add wrapperTemplate
option (#348)
This commit is contained in:
parent
96534ec59b
commit
2c07af8c69
3 changed files with 49 additions and 2 deletions
|
@ -1,5 +1,31 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
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`] = `
|
||||||
|
"# project
|
||||||
|
|
||||||
|
Description
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
These people contributed to the project:
|
||||||
|
<!-- ALL-CONTRIBUTORS-LIST:START -->
|
||||||
|
<!-- prettier-ignore-start -->
|
||||||
|
<!-- markdownlint-disable -->
|
||||||
|
<p>
|
||||||
|
<tr>
|
||||||
|
<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>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- markdownlint-restore -->
|
||||||
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||||
|
|
||||||
|
Thanks a lot everyone!"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors 1`] = `
|
exports[`replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of contributors 1`] = `
|
||||||
"# project
|
"# project
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,19 @@ test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a table of c
|
||||||
expect(result).toMatchSnapshot()
|
expect(result).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('replace the content between the ALL-CONTRIBUTORS-LIST tags by a custom wrapper around the list of contributors contained in the "bodyContent" tag', () => {
|
||||||
|
const {kentcdodds, bogas04} = contributors
|
||||||
|
const {options, jfmengels, content} = fixtures()
|
||||||
|
const contributorList = [kentcdodds, bogas04, jfmengels]
|
||||||
|
const result = generate(
|
||||||
|
Object.assign(options, { wrapperTemplate: '<p><%= bodyContent %></p>'}),
|
||||||
|
contributorList,
|
||||||
|
content,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(result).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
|
||||||
test('split contributors into multiples lines when there are too many', () => {
|
test('split contributors into multiples lines when there are too many', () => {
|
||||||
const {kentcdodds} = contributors
|
const {kentcdodds} = contributors
|
||||||
const {options, content} = fixtures()
|
const {options, content} = fixtures()
|
||||||
|
|
|
@ -66,6 +66,10 @@ function formatFooter(options) {
|
||||||
|
|
||||||
function generateContributorsList(options, contributors) {
|
function generateContributorsList(options, contributors) {
|
||||||
const tableFooter = formatFooter(options)
|
const tableFooter = formatFooter(options)
|
||||||
|
const defaultWrapperTemplate = _.template('\n<table>\n <tbody><%= bodyContent %> </tbody>\n<%= tableFooterContent %></table>\n\n')
|
||||||
|
const wrapperTemplate = options.wrapperTemplate ? _.template(`\n${options.wrapperTemplate}\n\n`) : defaultWrapperTemplate
|
||||||
|
const seperator = options.wrapperTemplate ? '\n </tr><br />\n <tr>\n ' : '\n </tr>\n <tr>\n '
|
||||||
|
|
||||||
let tableFooterContent = ''
|
let tableFooterContent = ''
|
||||||
|
|
||||||
return _.flow(
|
return _.flow(
|
||||||
|
@ -81,12 +85,15 @@ function generateContributorsList(options, contributors) {
|
||||||
_.map((currentLineContributors) => formatLine(
|
_.map((currentLineContributors) => formatLine(
|
||||||
options, currentLineContributors
|
options, currentLineContributors
|
||||||
)),
|
)),
|
||||||
_.join('\n </tr>\n <tr>\n '),
|
_.join(seperator),
|
||||||
newContent => {
|
newContent => {
|
||||||
if (options.linkToUsage) {
|
if (options.linkToUsage) {
|
||||||
tableFooterContent = ` <tfoot>\n ${tableFooter}\n </tfoot>\n`
|
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`
|
|
||||||
|
const bodyContent = `\n <tr>\n ${newContent}\n </tr>\n`
|
||||||
|
|
||||||
|
return wrapperTemplate({ bodyContent, tableFooterContent})
|
||||||
},
|
},
|
||||||
)(contributors)
|
)(contributors)
|
||||||
}
|
}
|
||||||
|
@ -135,6 +142,7 @@ module.exports = function generate(options, contributors, fileContent) {
|
||||||
? '\n'
|
? '\n'
|
||||||
: generateContributorsList(options, contributors)
|
: generateContributorsList(options, contributors)
|
||||||
const badge = formatBadge(options, contributors)
|
const badge = formatBadge(options, contributors)
|
||||||
|
|
||||||
return _.flow(
|
return _.flow(
|
||||||
injectListBetweenTags(contributorsList),
|
injectListBetweenTags(contributorsList),
|
||||||
replaceBadge(badge),
|
replaceBadge(badge),
|
||||||
|
|
Loading…
Reference in a new issue