Files
shields/services/wordpress/wordpress-version.service.js
Paul Melnikow 84a5be3946 Declare static examples using namedParams (#2308)
This continues the work from #2279, by allowing example badges to be specified using `namedParams`. Using an object makes it possible for us to display these in form fields down the line. (#701)

I've called this the "preferred" way, and labeled the other ways deprecated. I've also added some doc to the `examples` property in BaseService. Then I realized we had some doc in the tutorial, though I think it's fine to have a short version in the tutorial, and the gory detail in BaseService.

I've also added a `pattern` keyword, and made `urlPattern` an alias.

Closes #2050.
2018-11-17 09:47:25 -05:00

60 lines
1.3 KiB
JavaScript

'use strict'
const BaseWordpress = require('./wordpress-base')
const { addv } = require('../../lib/text-formatters')
const { version: versionColor } = require('../../lib/color-formatters')
function VersionForExtensionType(extensionType) {
const { capt, exampleSlug } = {
plugin: {
capt: 'Plugin',
exampleSlug: 'bbpress',
},
theme: {
capt: 'Theme',
exampleSlug: 'twentyseventeen',
},
}[extensionType]
return class WordpressPluginVersion extends BaseWordpress {
static get extensionType() {
return extensionType
}
static render({ response }) {
return {
message: addv(response.version),
color: versionColor(response.version),
}
}
static get category() {
return 'version'
}
static get defaultBadgeData() {
return { label: extensionType }
}
static get route() {
return {
base: `wordpress/${extensionType}/v`,
pattern: ':slug',
}
}
static get examples() {
return [
{
title: `Wordpress ${capt} Version`,
namedParams: { slug: exampleSlug },
staticExample: this.render({ response: { version: 2.5 } }),
keywords: ['wordpress'],
},
]
}
}
}
module.exports = ['theme', 'plugin'].map(VersionForExtensionType)