Module:Infobox/vNext
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Infobox/vNext/Documentation
local p = {}
local h = {}
local util = {
tables = {
concat = require("Module:Util/tables/concat")
}
}
-- Retrieves corresponding infobox configuration (e.g. [[Template:Infobox/Config/Character]])
-- and converts it the template spec format that [[Module:Documentation]] and [[Module:UtilsArg]] understand.
function p.templateSpec(config)
local baseConfig = mw.loadData("Module:Infobox/Config")
local optionParams = h.optionParams(baseConfig, config)
local params = util.tables.concat(
baseConfig.baseParams,
optionParams("addHiddenType") or {},
optionParams("inUniverse") or {},
config.addParams or {},
optionParams("addStrategy") or {}
)
local spec = {
params = {},
paramOrder = {}
}
for i, v in ipairs(params) do
table.insert(spec.paramOrder, v.param)
spec.params[v.param] = {
type = "string",
trim = true,
}
end
return spec
end
function h.optionParams(baseConfig, config)
return function(optionName)
if config[optionName] == nil or baseConfig.options[optionName] == nil then
return nil
end
local optionValue = config[optionName]
if type(optionValue) == "table" then -- used by addHiddenTypeParam whose value is a table
optionValue = true
end
local paramNames = baseConfig.options[optionName][optionValue]
if not paramNames then
return nil
end
local params = {}
for i, v in ipairs(paramNames) do
local param = baseConfig.optInParams[v]
if param then
table.insert(params, param)
end
end
return params
end
end
return p