Aller au contenu

Module:Fonctions

De Wikiquestia

La documentation pour ce module peut être créée à Module:Fonctions/doc

local p = {}

function p.multipleSuccession(frame)
    local args = frame.args
    local result = {}

    for i = 1, 5 do
        local titre = args["Titre"..i]
        local mandat = args["Mandat"..i]
        local charte = args["Charte"..i] or args["Charte"] or "defaut"
        local predecesseur = args["Prédécesseur"..i]
        local successeur = args["Successeur"..i]

        if titre and predecesseur and successeur then
            local mandatBlock = ""
            if mandat and mandat ~= "" then
                mandatBlock = '<div style="font-weight: normal; font-size: 90%;">' .. mw.text.encode(mandat) .. '</div>'
            end

            -- Appels au module Charte pour obtenir les couleurs
            local couleurFond = frame:callParserFunction('#invoke:Charte|couleur', 'charte=' .. charte .. '|type=titre')
            local couleurTexte = frame:callParserFunction('#invoke:Charte|couleur', 'charte=' .. charte .. '|type=texte')

            local bloc = 
                '<div style="margin: 0.5em 0; border: 1px solid #ccc; border-radius: 10px; overflow: hidden; font-size: 90%;">' ..
                '<div style="background-color: ' .. couleurFond .. '; ' ..
                'color: ' .. couleurTexte .. '; text-align: center; padding: 0.5em; font-weight: bold;">' ..
                mw.text.encode(titre) .. mandatBlock .. 
                '</div>' ..
                '<div style="display: flex; justify-content: space-between; align-items: center; padding: 0.5em;">' ..
                '<div style="text-align: left; flex: 1;">← [[' .. mw.text.encode(predecesseur) .. ']]</div>' ..
                '<div style="flex: 0 0 auto; padding: 0 1em;">·</div>' ..
                '<div style="text-align: right; flex: 1;">[[' .. mw.text.encode(successeur) .. ']] →</div>' ..
                '</div></div>'

            table.insert(result, bloc)
        end
    end

    return table.concat(result, "\n")
end

return p