-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style(generate): changed generator to an HTML based one [WIP]
I added and set the HTML generator for resolving #154 (which works when testing manually but doesn't when running the cli in dev mode). fix #154
- Loading branch information
1 parent
48fecd3
commit 2babe26
Showing
8 changed files
with
167 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const _ = require('lodash/fp') | ||
|
||
const util = require('../util') | ||
|
||
const linkTemplate = _.template( | ||
'<a href="<%= url %>" title="<%= description %>"><%= symbol %></a>', | ||
) | ||
|
||
function getType(options, contribution) { | ||
const types = util.contributionTypes(options) | ||
return types[contribution.type || contribution] | ||
} | ||
|
||
module.exports = function formatContribution( | ||
options, | ||
contributor, | ||
contribution, | ||
) { | ||
const type = getType(options, contribution) | ||
|
||
if (!type) { | ||
throw new Error( | ||
`Unknown contribution type ${contribution} for contributor ${contributor.login || | ||
contributor.name}`, | ||
) | ||
} | ||
|
||
const templateData = { | ||
symbol: type.symbol, | ||
description: type.description, | ||
contributor, | ||
options, | ||
} | ||
|
||
let url = getUrl(contribution, contributor) | ||
|
||
if (contribution.url) { | ||
url = contribution.url | ||
} else if (type.link) { | ||
url = _.template(type.link)(templateData) | ||
} | ||
|
||
return linkTemplate(_.assign({url}, templateData)) | ||
} | ||
|
||
function getUrl(contribution, contributor) { | ||
if (contributor.login) { | ||
return `#${contribution}-${contributor.login}` | ||
} else { | ||
return `#${contribution}` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const _ = require('lodash/fp') | ||
const formatContributionType = require('./format-contribution-type-html') | ||
|
||
const avatarTemplate = _.template( | ||
'<img src="<%= contributor.avatar_url %>" width="<%= options.imageSize %>px;" alt="<%= name %>"/>', | ||
) | ||
const avatarBlockTemplate = _.template( | ||
'<a href="<%= contributor.profile %>"><%= avatar %><br /><sub><b><%= name %></b></sub></a>', | ||
) | ||
const avatarBlockTemplateNoProfile = _.template( | ||
'<%= avatar %><br /><sub><b><%= name %></b></sub>', | ||
) | ||
const contributorTemplate = _.template( | ||
'<%= avatarBlock %><br /><%= contributions %>', | ||
) | ||
|
||
const defaultImageSize = 100 | ||
|
||
function defaultTemplate(templateData) { | ||
const name = escapeName(templateData.contributor.name) | ||
const avatar = avatarTemplate( | ||
_.assign(templateData, { | ||
name, | ||
}), | ||
) | ||
const avatarBlockTemplateData = _.assign( | ||
{ | ||
name, | ||
avatar, | ||
}, | ||
templateData, | ||
) | ||
let avatarBlock = null | ||
|
||
if (templateData.contributor.profile) { | ||
avatarBlock = avatarBlockTemplate(avatarBlockTemplateData) | ||
} else { | ||
avatarBlock = avatarBlockTemplateNoProfile(avatarBlockTemplateData) | ||
} | ||
|
||
return contributorTemplate(_.assign({avatarBlock}, templateData)) | ||
} | ||
|
||
function escapeName(name) { | ||
return name.replace(new RegExp('\\|', 'g'), '|') | ||
} | ||
|
||
module.exports = function formatContributor(options, contributor) { | ||
const formatter = _.partial(formatContributionType, [options, contributor]) | ||
const contributions = contributor.contributions.map(formatter).join(' ') | ||
const templateData = { | ||
contributions, | ||
contributor, | ||
options: _.assign({imageSize: defaultImageSize}, options), | ||
} | ||
const customTemplate = | ||
options.contributorTemplate && _.template(options.contributorTemplate) | ||
return (customTemplate || defaultTemplate)(templateData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters