Module:Infobox/DocGen
Jump to navigation
Jump to search
This module generates documentation for Module:Infobox/Config and its subpages.
local p = {}
local Documentation = require("Module:Documentation")
local Infobox = require("Module:Infobox/vNext")
local utilsSchema = require("Module:UtilsSchema")
function p.Template(frame)
local subjectType = frame.args[1]
local spec = Infobox.templateSpec(subjectType)
local config = mw.loadData("Module:Infobox/Config/"..subjectType)
-- "purpose" part of spec is added here because it's purely documentation
-- Otherwise changing purpose text would add all mainspace articles using infoboxes to job queue
spec.purpose = string.format("[[Zelda Wiki:Glossary#Infobox|Infobox]] template for [[:%s|%s articles]].", config.category, subjectType)
spec.categories = {config.inUniverse and "Category:In-universe infobox templates" or "Category:Real world infobox templates"}
local doc = Documentation.printTemplateDoc("Module:Infobox", "Template:Infobox "..subjectType, spec)
return doc
end
function p.ValidateBaseConfig(frame)
local cats = ""
local schema = p.Schemas().ConfigBasePage
local config = mw.loadData("Module:Infobox/Config")
local errSchema = utilsSchema.validate(schema, "ConfigBasePage", config, "Config")
if errSchema then
cats = cats.."[[Category:Modules with invalid data]]"
end
return cats
end
function p.InfoboxConfig(frame)
local title = mw.title.getCurrentTitle()
local cats = p.categorize(title)
local subjectType = p.extractSubjectType(title)
local text = frame:expandTemplate({
title = "Template:Infobox Config Doc",
args = {subjectType}
})
local schema, schemaValidationCats = p.applySchema(subjectType)
local schemaCollapsible = frame:expandTemplate({
title = "Template:Collapsible",
args = {
header = "Schema",
content = schema,
}
})
text = text..schemaCollapsible
cats = cats..schemaValidationCats
return text, cats
end
function p.categorize(title)
if title.subpageText == "Documentation" then
return "[[Category:Module Data Documentation]]"
else
return "[[Category:Module Data]][[Category:Infobox configuration pages]]"
end
end
function p.extractSubjectType(title)
if title.subpageText == "Documentation" then
return mw.title.new(title.baseText).subpageText
else
return title.subpageText
end
end
function p.applySchema(subjectType)
local cats = ""
local schema = p.Schemas().ConfigSubpage
local config = mw.loadData("Module:Infobox/Config/"..subjectType)
local errSchema = utilsSchema.validate(schema, "ConfigSubpage", config, "/Config/"..subjectType)
if errSchema then
cats = cats.."[[Category:Modules with invalid data]]"
end
local schemaDef = Documentation.schema(schema, "Config")
return schemaDef, cats
end
function p.Schemas()
return {
ConfigBasePage = {
type = "record",
required = true,
properties = {
{
name = "baseParams",
type = "array",
required = true,
desc = "Defines the essential parameters that all infoboxes share.",
items = {
type = "record",
properties = {
{
name = "param",
type = "string",
required = true,
desc = "The name of the template parameter.",
},
{
name = "descr",
type = "string",
required = true,
desc = "A description of the parameter for the infobox template's documentation page.",
},
},
},
},
{
name = "optInParams",
type = "map",
required = true,
desc = "Defines parameters that are common across several infoboxes. Infobox configurations receive these parameters by setting an <code>option</code> property as defined below.",
keyPlaceholder = "paramKey",
keys = {
type = "string",
desc = "The string used in <code>options</code> to reference a specific opt-in parameter.",
},
values = {
type = "record",
properties = {
{
name = "param",
type = "string",
required = true,
desc = "The name of the template parameter corresponding to the infobox field."
},
{
name = "label",
type = "string",
desc = "<p>The label for the infobox field, i.e. the header text displayed in the left column.</p>"
.. "<p>Can be left blank for special fields that have no label, where the value spans the width of the infobox.</p>"
},
{
name = "descr",
type = "string",
required = true,
desc = "A description of the infobox field for the infobox template's documentation.",
},
},
},
},
{
name = "options",
type = "map",
desc = "Defines properties that can be used in infobox config to opt in to some of the paramers in <code>optInParams</code>.",
required = true,
keyPlaceholder = "optionName",
keys = { type = "string" },
values = {
type = "any",
-- Should work but seems to be broken
-- type = "map",
-- keys = { type = "any" },
-- values = {
-- type = "array",
-- items = { type = "string" },
-- },
},
},
},
},
ConfigSubpage = {
type = "record",
required = true,
properties = {
{
name = "category",
type = "string",
required = true,
desc = "The name of the category to be added automatically by the infobox. Should be a subcategory of [[:Category:Content by Type]].",
},
{
name = "inUniverse",
type = "boolean",
required = true,
desc = "Infobox fields common to in-universe or real-world subjects are added automatically based on the value of this property."
.. " For a list of such properties, see [[Module:Infobox/Config]]. Should one or more of these fields not be desirable for this particular infobox, they can be omitted via the <code>omitParams</code> property (see below).",
},
{
name = "omitParams",
type = "array",
items = { type = "string" },
desc = "List of parameters to omit from those added automatically according to the value of the <code>inUniverse</code> property.",
},
{
name = "addHiddenType",
type = "map",
keys = { type = "string" },
values = { type = "any" },
desc = "<p>If present, adds a <code>type</code> parameter which is not displayed in the infobox, but used internally to subcategorize the page it's used on.</p>"
.. "<p><b>This form of categorization is an outdated practice.</b> It has been deprecated in favor of using [[Template:Categories]].</p>"
},
{
name = "addParams",
type = "array",
desc = "Fields to add to the infobox.",
items = {
type = "record",
properties = {
{
name = "param",
type = "string",
required = true,
desc = "The name of the template parameter corresponding to the infobox field."
},
{
name = "label",
type = "string",
required = true,
desc = "The label for the infobox field, i.e. the header text displayed in the left column.",
},
{
name = "descr",
type = "string",
required = true,
desc = "A description of the infobox field for the infobox template's documentation.",
},
},
},
},
},
},
}
end
return p