Módulo:Infobox
De Cronicas Eternas Wiki
A documentação para este módulo pode ser criada em Módulo:Infobox/doc
local p = {}
-- Lista de valores que indicam ausência de informação
local ignoredValues = {
["Unknown"] = true,
["None"] = true,
["Nenhum"] = true,
["-"] = true,
["--"] = true,
[""] = true
}
function p.infobox(frame)
local args = frame:getParent().args
-- Lista ordenada de seções
local orderedSections = {
"Geografia",
"Política",
"Sociedade",
"Comércio"
}
-- Tabela com os campos das seções
local sections = {
["Geografia"] = {
{"Conhecido(a) como", args["known_as"]},
{"Tipo", args["type"]},
{"Região", args["region"]},
{"Tamanho", args["size"]},
{"Elevação", args["elevation"]},
{"Profundidade", args["depth"]},
{"Capital", args["capital"]},
},
["Política"] = {
{"Tipo de Governo", args["government_type"]},
{"Tipo de Regente", args["ruler_type"]},
{"Regente Atual", args["current_ruler"]},
{"Poder Executivo", args["executive"]},
{"Poder Legislativo", args["legislative"]},
{"Poder Judiciário", args["judiciary"]},
{"Alianças", args["alliances"]},
},
["Sociedade"] = {
{"Gentílico", args["demonym"]},
{"População", args["population"]},
{"Espécies", args["species"]},
{"Linguagens", args["languages"]},
{"Religiões", args["religions"]},
},
["Comércio"] = {
{"Importações", args["imports"]},
{"Exportações", args["exports"]},
{"Cunhagem", args["currency"]},
},
}
-- Início da infobox
local infobox = '<div style="width:22em; background:#f9f9f9; border:1px solid #aaa; float:right; padding:5px; font-size:90%;">'
-- Itera sobre as seções na ordem definida
for _, section in ipairs(orderedSections) do
local fields = sections[section]
local sectionContent = {}
-- Monta os campos da seção com valores válidos
for _, field in ipairs(fields) do
local label, value = field[1], field[2]
-- Verifica se o valor é válido (não está na lista de ignorados)
if value and not ignoredValues[value:match("^%s*(.-)%s*$")] then
table.insert(sectionContent, string.format('<div style="padding:2px 5px;"><strong>%s:</strong> %s</div>', label, value))
end
end
-- Renderiza a seção somente se houver conteúdo
if #sectionContent > 0 then
infobox = infobox .. string.format('<div style="text-align:center; background:#ccc; font-size:120%%; padding:4px;">%s</div>', section)
infobox = infobox .. table.concat(sectionContent)
end
end
infobox = infobox .. '</div>'
return infobox
end
return p