@@ -1,53 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const coalesce = require('../core/base-service/coalesce')
|
||||
const toArray = require('../core/base-service/to-array')
|
||||
const { makeLogo } = require('./logos')
|
||||
|
||||
function makeLabel(defaultLabel, overrides) {
|
||||
return `${
|
||||
overrides.label === undefined
|
||||
? (defaultLabel || '').toLowerCase()
|
||||
: overrides.label
|
||||
}`
|
||||
}
|
||||
|
||||
// Generate the initial badge data. Pass the URL query parameters, which
|
||||
// override the default label.
|
||||
//
|
||||
// The following parameters are supported:
|
||||
//
|
||||
// - label
|
||||
// - style
|
||||
// - logo
|
||||
// - logoWidth
|
||||
// - link
|
||||
// - color and colorB
|
||||
// - labelColor and colorA
|
||||
// - maxAge
|
||||
// - cacheSeconds
|
||||
//
|
||||
// Note: `maxAge` and `cacheSeconds` are handled by cache(), not this function.
|
||||
function makeBadgeData(defaultLabel, overrides) {
|
||||
const colorA = coalesce(overrides.labelColor, overrides.colorA)
|
||||
const colorB = coalesce(overrides.color, overrides.colorB)
|
||||
|
||||
return {
|
||||
text: [makeLabel(defaultLabel, overrides), 'n/a'],
|
||||
colorscheme: 'lightgrey',
|
||||
template: overrides.style,
|
||||
logo: makeLogo(undefined, overrides),
|
||||
logoPosition: +overrides.logoPosition,
|
||||
logoWidth: +overrides.logoWidth,
|
||||
links: toArray(overrides.link),
|
||||
// Scoutcamp sometimes turns these into numbers.
|
||||
colorA: typeof colorA === 'number' ? `${colorA}` : colorA,
|
||||
colorB: typeof colorB === 'number' ? `${colorB}` : colorB,
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
toArray,
|
||||
makeLabel,
|
||||
makeBadgeData,
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const { test, given } = require('sazerac')
|
||||
const { makeLabel, makeBadgeData } = require('./badge-data')
|
||||
|
||||
describe('Badge data helpers', function() {
|
||||
test(makeLabel, () => {
|
||||
given('my badge', {}).expect('my badge')
|
||||
given('My bAdge', {}).expect('my badge')
|
||||
given('my badge', { label: 'no, my badge' }).expect('no, my badge')
|
||||
given('my badge', { label: 'no, MY badge' }).expect('no, MY badge')
|
||||
given('my badge', { label: false }).expect('false')
|
||||
given('my badge', { label: 0 }).expect('0')
|
||||
given('my badge', { label: '' }).expect('')
|
||||
})
|
||||
|
||||
test(makeBadgeData, () => {
|
||||
given('my badge', {
|
||||
label: 'no, my badge',
|
||||
style: 'flat-square',
|
||||
logo: 'image/svg+xml;base64,PHN2ZyB4bWxu',
|
||||
logoPosition: 10,
|
||||
logoWidth: '25',
|
||||
link: 'https://example.com/',
|
||||
colorA: 'blue',
|
||||
colorB: 'f00bae',
|
||||
}).expect({
|
||||
text: ['no, my badge', 'n/a'],
|
||||
colorscheme: 'lightgrey',
|
||||
template: 'flat-square',
|
||||
logo: 'data:image/svg+xml;base64,PHN2ZyB4bWxu',
|
||||
logoPosition: 10,
|
||||
logoWidth: 25,
|
||||
links: ['https://example.com/'],
|
||||
colorA: 'blue',
|
||||
colorB: 'f00bae',
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user