Skip to content

Commit

Permalink
Refactor WordpressPluginTestedVersion to use renderVersionBadge
Browse files Browse the repository at this point in the history
  • Loading branch information
jNullj committed Oct 16, 2024
1 parent 6a02951 commit ec97261
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions services/wordpress/wordpress-platform.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { NotFound, pathParams } from '../index.js'
import { addv } from '../text-formatters.js'
import { renderVersionBadge } from '../version.js'
import { version as versionColor } from '../color-formatters.js'
import { description, BaseWordpress } from './wordpress-base.js'
Expand Down Expand Up @@ -87,21 +86,18 @@ class WordpressPluginTestedVersion extends BaseWordpress {

static defaultBadgeData = { label: 'wordpress' }

static async render({ testedVersion }) {
// Atypically, the `render()` function of this badge is `async` because it needs to pull
// data from the server.
return {
message: `${addv(testedVersion)} tested`,
color: await versionColorForWordpressVersion(testedVersion),
}
}

async handle({ slug }) {
const { tested: testedVersion } = await this.fetch({
extensionType: 'plugin',
slug,
})
return this.constructor.render({ testedVersion })
// Atypically, pulling color data from the server with async operation.
const color = await versionColorForWordpressVersion(testedVersion)
return renderVersionBadge({
version: testedVersion,
postfix: 'tested',
versionFormatter: () => color,
})
}
}

Expand Down

0 comments on commit ec97261

Please sign in to comment.