Module:Infobox Player
Appearance
Documentation for this module may be created at Module:Infobox Player/doc
local infobox = require('Module:Infobox')
local p = {}
local function humanLabel(key)
key = mw.ustring.gsub(key, "%-", " ")
return mw.ustring.upper(mw.ustring.sub(key,1,1)) .. mw.ustring.sub(key,2)
end
local sections = {
["Basic Information"] = { "season-joined", "nationality", "discord" },
}
function p.infobox(frame)
local args = frame:getParent().args
local used = {}
local outArgs = { title = args.username }
local rowCount = 0
local catCount = 0
for sectionName, keys in pairs(sections) do
local hasData = false
for _, k in ipairs(keys) do
if args[k] and args[k] ~= "" then hasData = true; break end
end
if hasData then
catCount = catCount + 1
outArgs["category" .. catCount] = sectionName
for _, k in ipairs(keys) do
if args[k] and args[k] ~= "" then
rowCount = rowCount + 1
outArgs["label" .. rowCount] = humanLabel(k)
outArgs["data" .. rowCount] = args[k]
used[k] = true
end
end
end
end
local extraKeys = {}
for k, v in pairs(args) do
if k ~= "username" and v and v ~= "" and not used[k] then
table.insert(extraKeys, k)
end
end
if #extraKeys > 0 then
catCount = catCount + 1
outArgs["category" .. catCount] = "Additional Data"
table.sort(extraKeys)
for _, k in ipairs(extraKeys) do
rowCount = rowCount + 1
outArgs["label" .. rowCount] = humanLabel(k)
outArgs["data" .. rowCount] = args[k]
end
end
outArgs.rows = rowCount
outArgs.categories = catCount
return infobox.infobox{
getParent = function() return { args = outArgs } end
}
end
return p