support doc overrides for inputs & fields
This commit is contained in:
parent
31cbbfb3a4
commit
da3a86f55d
3 changed files with 50 additions and 2 deletions
|
|
@ -18,6 +18,7 @@ class BlockDefinition {
|
||||||
name = null
|
name = null
|
||||||
|
|
||||||
description = ''
|
description = ''
|
||||||
|
docOverrides = {}
|
||||||
ioPlus = false
|
ioPlus = false
|
||||||
|
|
||||||
colour = null
|
colour = null
|
||||||
|
|
@ -178,6 +179,7 @@ BlockDefinition.parseRawDefinition = function(rawBlockDefinition, definitionPath
|
||||||
blockDef.type = rawBlockDefinition.type
|
blockDef.type = rawBlockDefinition.type
|
||||||
blockDef.name = rawBlockDefinition.name
|
blockDef.name = rawBlockDefinition.name
|
||||||
blockDef.primaryCategory = rawBlockDefinition.primaryCategory
|
blockDef.primaryCategory = rawBlockDefinition.primaryCategory
|
||||||
|
blockDef.docOverrides = rawBlockDefinition.docOverrides
|
||||||
blockDef.description = rawBlockDefinition.description
|
blockDef.description = rawBlockDefinition.description
|
||||||
? niceTemplate(rawBlockDefinition.description)
|
? niceTemplate(rawBlockDefinition.description)
|
||||||
: ""
|
: ""
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
import { capitalize, map, mapValues, values } from 'lodash-es'
|
import { capitalize, keys, map, mapValues, pickBy, values } from 'lodash-es'
|
||||||
|
|
||||||
import { niceTemplate } from '#src/util.js'
|
import { niceTemplate } from '#src/util.js'
|
||||||
|
|
||||||
|
|
||||||
const
|
const
|
||||||
renderFields = definition => {
|
renderFields = definition => {
|
||||||
|
if(definition.docOverrides?.fields) {
|
||||||
|
return renderOverridenFields(definition)
|
||||||
|
}
|
||||||
|
|
||||||
const fields = values(mapValues(definition.fields, (newField, name) => {
|
const fields = values(mapValues(definition.fields, (newField, name) => {
|
||||||
newField.field = name
|
newField.field = name
|
||||||
return newField
|
return newField
|
||||||
|
|
@ -15,6 +19,22 @@ const
|
||||||
return fields.map(renderField).join("\n\n")
|
return fields.map(renderField).join("\n\n")
|
||||||
},
|
},
|
||||||
|
|
||||||
|
renderOverridenFields = definition => {
|
||||||
|
// warn if any inputs have descriptions that won't be rendered
|
||||||
|
const
|
||||||
|
{ fields } = definition.docOverrides,
|
||||||
|
missedFields = keys(pickBy(definition.fields, "description")).join(", ")
|
||||||
|
|
||||||
|
if(missedFields) {
|
||||||
|
console.warn(`Warning [${definition.type}]: Inputs doc is overriden, input descriptions will not be seen for: ${missedFields}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// determine if the override is a function to call
|
||||||
|
return niceTemplate(typeof fields === 'string'
|
||||||
|
? fields
|
||||||
|
: fields(definition))
|
||||||
|
},
|
||||||
|
|
||||||
renderField = field => {
|
renderField = field => {
|
||||||
const lines = []
|
const lines = []
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,38 @@
|
||||||
import { capitalize, forEach, keys } from 'lodash-es'
|
import { capitalize, pickBy, forEach, keys } from 'lodash-es'
|
||||||
|
|
||||||
|
import { niceTemplate } from '#src/util.js'
|
||||||
|
|
||||||
|
|
||||||
const
|
const
|
||||||
renderInputs = definition => {
|
renderInputs = definition => {
|
||||||
|
if(definition.docOverrides?.inputs) {
|
||||||
|
return renderOverridenInputs(definition)
|
||||||
|
}
|
||||||
|
|
||||||
if(!keys(definition.inputs).length) {
|
if(!keys(definition.inputs).length) {
|
||||||
return "This block has no inputs"
|
return "This block has no inputs"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return renderEachInput(definition)
|
||||||
|
},
|
||||||
|
|
||||||
|
renderOverridenInputs = definition => {
|
||||||
|
// warn if any inputs have descriptions that won't be rendered
|
||||||
|
const
|
||||||
|
{ inputs } = definition.docOverrides,
|
||||||
|
missedInputs = keys(pickBy(definition.inputs, "description")).join(", ")
|
||||||
|
|
||||||
|
if(missedInputs) {
|
||||||
|
console.warn(`Warning [${definition.type}]: Inputs doc is overriden, input descriptions will not be seen for: ${missedInputs}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// determine if the override is a function to call
|
||||||
|
return niceTemplate(typeof inputs === 'string'
|
||||||
|
? inputs
|
||||||
|
: inputs(definition))
|
||||||
|
},
|
||||||
|
|
||||||
|
renderEachInput = definition => {
|
||||||
const lines = []
|
const lines = []
|
||||||
forEach(definition.inputs, (input, inputName) => {
|
forEach(definition.inputs, (input, inputName) => {
|
||||||
if(input.type === 'label') { return }
|
if(input.type === 'label') { return }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue