Módulo:Infobox: mudanças entre as edições
De Cronicas Eternas Wiki
Criou página com 'local p = {} function p.infobox(frame) local args = frame:getParent().args local title = args['title'] or 'Título Padrão' local description = args['description'] or 'Sem descrição' local date = args['date'] or 'Desconhecido' local image = args['image'] or '' return string.format([[ <div style="width:22em; background:#f9f9f9; border:1px solid #aaa; float:right; padding:5px; font-size:90%;"> <div style="text-align:center; backgroun...' |
Sem resumo de edição |
||
(3 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
Linha 1: | Linha 1: | ||
local p = {} | 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) | function p.infobox(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
-- Lista ordenada de seções | |||
<div style="width:22em; background:#f9f9f9; border:1px solid #aaa; float:right; padding:5px; font-size:90%;"> | local orderedSections = { | ||
"Geografia", | |||
"Política", | |||
"Sociedade", | |||
"Comércio" | |||
</div> | } | ||
-- 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 | end | ||
return p | return p |
Edição atual tal como às 15h20min de 26 de novembro de 2024
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