-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a render helper for downloads badges, run [amo ansible apm chrome…
…webstore clojars conda crates docker dub eclipse gem githubdownloads] (#7163) * refactor: add render helper for downloads badges * refactor: use new helper in some download badge classes * doc renderer function Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
- Loading branch information
1 parent
6df390e
commit e4e7b09
Showing
15 changed files
with
172 additions
and
148 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
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 @@ | ||
import { downloadCount } from './color-formatters.js' | ||
import { metric } from './text-formatters.js' | ||
|
||
/** | ||
* Handles rendering concerns of badges that display | ||
* download counts, with override/customization support | ||
* | ||
* @param {object} attrs Refer to individual attrs | ||
* @param {number} attrs.downloads Number of downloads | ||
* @param {string} [attrs.interval] Period or interval the downloads occurred | ||
* (e.g. day, week, month). If provided then this Will be reflected | ||
* in the badge message unless overridden by other message-related parameters | ||
* @param {string} [attrs.version] Version or tag that was downloaded | ||
* which will be reflected in the badge label (unless the label is overridden) | ||
* @param {string} [attrs.labelOverride] If provided then the badge label is set to this | ||
* value overriding any other label-related parameters | ||
* @param {string} [attrs.colorOverride] If provided then the badge color is set to this | ||
* value instead of the color being based on the count of downloads | ||
* @param {string} [attrs.messageSuffixOverride] If provided then the badge message will | ||
* will have this value added to the download count, separated with a space | ||
* @returns {object} Badge | ||
*/ | ||
function renderDownloadsBadge({ | ||
downloads, | ||
interval, | ||
version, | ||
labelOverride, | ||
colorOverride, | ||
messageSuffixOverride, | ||
}) { | ||
let messageSuffix = '' | ||
if (messageSuffixOverride) { | ||
messageSuffix = ` ${messageSuffixOverride}` | ||
} else if (interval) { | ||
messageSuffix = `/${interval}` | ||
} | ||
|
||
let label | ||
if (labelOverride) { | ||
label = labelOverride | ||
} else if (version) { | ||
label = `downloads@${version}` | ||
} | ||
|
||
return { | ||
label, | ||
color: colorOverride || downloadCount(downloads), | ||
message: `${metric(downloads)}${messageSuffix}`, | ||
} | ||
} | ||
|
||
export { renderDownloadsBadge } |
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,43 @@ | ||
import { test, given } from 'sazerac' | ||
import { renderDownloadsBadge } from './downloads.js' | ||
import { downloadCount } from './color-formatters.js' | ||
import { metric } from './text-formatters.js' | ||
|
||
const downloads = 2345 | ||
const message = metric(downloads) | ||
const color = downloadCount(downloads) | ||
|
||
describe('downloads', function () { | ||
test(renderDownloadsBadge, () => { | ||
given({ downloads }).expect({ label: undefined, color, message }) | ||
given({ downloads, labelOverride: 'recent downloads' }).expect({ | ||
label: 'recent downloads', | ||
color, | ||
message, | ||
}) | ||
given({ downloads, version: 'v1.0.0' }).expect({ | ||
label: '[email protected]', | ||
color, | ||
message, | ||
}) | ||
given({ | ||
downloads, | ||
messageSuffixOverride: '[foo.tar.gz]', | ||
interval: 'week', | ||
}).expect({ | ||
label: undefined, | ||
color, | ||
message: `${message} [foo.tar.gz]`, | ||
}) | ||
given({ downloads, interval: 'year' }).expect({ | ||
label: undefined, | ||
color, | ||
message: `${message}/year`, | ||
}) | ||
given({ downloads, colorOverride: 'pink' }).expect({ | ||
label: undefined, | ||
color: 'pink', | ||
message, | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.