Módulo:SpellInfobox: 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 sections = { ["INFORMAÇÕES DO FEITIÇO"] = { {"Nome", args["name"]}, {"Divindade", args["deity"]}, {"Criador", args["creator"]}, {"Classes", args["classes"]}, {"Escola", args["school"]}, {"Nível", args["level"]}, }, } -- Início da infobox com o nome local infobox = '<div style="...'
 
Sem resumo de edição
 
(Uma revisão intermediária pelo mesmo usuário não está sendo mostrada)
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)
Linha 5: Linha 15:


     local sections = {
     local sections = {
         ["INFORMAÇÕES DO FEITIÇO"] = {
         {
            {"Nome", args["name"]},
            title = "INFORMAÇÕES DO FEITIÇO",
            {"Divindade", args["deity"]},
            fields = {
            {"Criador", args["creator"]},
                {"Nome", args["name"]},
            {"Classes", args["classes"]},
                {"Divindade", args["deity"]},
            {"Escola", args["school"]},
                {"Criador", args["creator"]},
            {"Nível", args["level"]},
                {"Classes", args["classes"]},
                {"Escola", args["school"]},
                {"Nível", args["level"]},
            },
         },
         },
     }
     }


     -- Início da infobox com o nome
     -- Início da infobox
     local infobox = '<div style="width:22em; background:#f9f9f9; border:1px solid #aaa; float:right; padding:5px; font-size:90%;">'
     local infobox = '<div style="width:22em; background:#f9f9f9; border:1px solid #aaa; float:right; padding:5px; font-size:90%;">'


     -- Adiciona o nome do feitiço no topo
    -- Adiciona a imagem no topo, se fornecida
    if args["image"] and args["image"] ~= "" then
        infobox = infobox .. string.format(
            '<div style="text-align:center; margin-bottom:10px;">%s</div>',
            frame:preprocess(string.format('[[File:%s|center|frameless|200px]]', args["image"]))
        )
    end
 
     -- Adiciona o nome do feitiço
     infobox = infobox .. string.format(
     infobox = infobox .. string.format(
         '<div style="text-align:center; background:#ccc; font-size:120%%; padding:4px;">%s</div>',
         '<div style="text-align:center; background:#ccc; font-size:120%%; padding:4px;">%s</div>',
Linha 24: Linha 45:
     )
     )


     -- Adiciona as seções e campos
     -- Adiciona as seções e os campos
     for section, fields in pairs(sections) do
     for _, section in ipairs(sections) do
         infobox = infobox .. string.format('<div style="text-align:center; background:#ddd; font-size:110%%; padding:4px; margin-top:5px;">%s</div>', section)
         local sectionContent = {}
         for _, field in ipairs(fields) do
 
        -- Monta os campos com conteúdo da seção
         for _, field in ipairs(section.fields) do
             local label, value = field[1], field[2]
             local label, value = field[1], field[2]
             if value and value ~= "" then
            -- Verifica se o valor é válido (não está na lista de ignorados)
                 infobox = infobox .. string.format('<div style="padding:2px 5px;"><strong>%s:</strong> %s</div>', label, value)
             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
        end
        -- Adiciona a seção somente se tiver conteúdo
        if #sectionContent > 0 then
            infobox = infobox .. string.format('<div style="text-align:center; background:#ddd; font-size:110%%; padding:4px; margin-top:5px;">%s</div>', section.title)
            infobox = infobox .. table.concat(sectionContent)
         end
         end
     end
     end

Edição atual tal como às 00h13min de 24 de novembro de 2024

A documentação para este módulo pode ser criada em Módulo:SpellInfobox/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

    local sections = {
        {
            title = "INFORMAÇÕES DO FEITIÇO",
            fields = {
                {"Nome", args["name"]},
                {"Divindade", args["deity"]},
                {"Criador", args["creator"]},
                {"Classes", args["classes"]},
                {"Escola", args["school"]},
                {"Nível", args["level"]},
            },
        },
    }

    -- Início da infobox
    local infobox = '<div style="width:22em; background:#f9f9f9; border:1px solid #aaa; float:right; padding:5px; font-size:90%;">'

    -- Adiciona a imagem no topo, se fornecida
    if args["image"] and args["image"] ~= "" then
        infobox = infobox .. string.format(
            '<div style="text-align:center; margin-bottom:10px;">%s</div>',
            frame:preprocess(string.format('[[File:%s|center|frameless|200px]]', args["image"]))
        )
    end

    -- Adiciona o nome do feitiço
    infobox = infobox .. string.format(
        '<div style="text-align:center; background:#ccc; font-size:120%%; padding:4px;">%s</div>',
        args["name"] or "NOME DO FEITIÇO"
    )

    -- Adiciona as seções e os campos
    for _, section in ipairs(sections) do
        local sectionContent = {}

        -- Monta os campos com conteúdo da seção
        for _, field in ipairs(section.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

        -- Adiciona a seção somente se tiver conteúdo
        if #sectionContent > 0 then
            infobox = infobox .. string.format('<div style="text-align:center; background:#ddd; font-size:110%%; padding:4px; margin-top:5px;">%s</div>', section.title)
            infobox = infobox .. table.concat(sectionContent)
        end
    end

    infobox = infobox .. '</div>'

    return infobox
end

return p