Module:Infobox/DocGen: Difference between revisions

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search
m (PhantomCaleb moved page Module:Infobox/DocGen to Module:Infobox/ConfigDocGen without leaving a redirect)
No edit summary
Line 1: Line 1:
local p = {}
local p = {}
local DocumentationModule = require("Module:Documentation/Module")
local utilsSchema = require("Module:UtilsSchema")


function p.Main(frame)
function p.Main(frame)
Line 10: Line 13:
args = {subjectType}
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
return text, cats
Line 28: Line 42:
return title.subpageText
return title.subpageText
end
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 = DocumentationModule.schema(schema, "Config")
return schemaDef, cats
end
function p.Schemas()
return {
ConfigBasePage = {
type = "record",
required = true,
properties = {},
},
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
end


return p
return p

Revision as of 19:09, 21 April 2024

This module generates documentation for Module:Infobox/Config and its subpages.


local p = {}

local DocumentationModule = require("Module:Documentation/Module")
local utilsSchema = require("Module:UtilsSchema")

function p.Main(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 = DocumentationModule.schema(schema, "Config")

	return schemaDef, cats
end

function p.Schemas()
	return {
		ConfigBasePage = {
			type = "record",
			required = true,
			properties = {},
		},
		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