Module:Infobox/vNext: Difference between revisions
Jump to navigation
Jump to search
PhantomCaleb (talk | contribs) No edit summary |
PhantomCaleb (talk | contribs) No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local h = {} | |||
local util = { | |||
tables = { | |||
concat = require("Module:Util/tables/concat") | |||
} | |||
} | |||
-- Retrieves corresponding infobox configuration (e.g. [[Template:Infobox/Config/Character]]) | -- Retrieves corresponding infobox configuration (e.g. [[Template:Infobox/Config/Character]]) | ||
-- and converts it the template spec format that [[Module:Documentation]] and [[Module:UtilsArg]] understand. | -- and converts it the template spec format that [[Module:Documentation]] and [[Module:UtilsArg]] understand. | ||
function p.templateSpec( | function p.templateSpec(config) | ||
local | 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 | 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 | end | ||
return p | return p |
Latest revision as of 15:50, 12 May 2024
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