Aller au contenu

« Module:Fonctions » : différence entre les versions

De Wikiquestia
Aucun résumé des modifications
Balise : Révoqué
Aucun résumé des modifications
Balise : Révocation manuelle
Ligne 1 : Ligne 1 :
local p = {}
local p = {}
local charteModule = require("Module:Charte")
local charteModule = require("Module:Charte") -- appel direct à ton module Charte


function p.multipleSuccession(frame)
function p.multipleSuccession(frame)
     local args = frame.args
     local args = frame.args
     local titre = args["Titre"]
     local result = {}
    if not titre or titre == "" then
        return ""
    end


    -- Couleurs calculées une seule fois en dehors de la boucle
     local charte = args["Charte"] or "defaut"
     local charte = args["Charte"] or "defaut"
     local couleurFond = charteModule.couleur{ args = { charte = charte, type = "titre" } }
     local couleurFond = charteModule.couleur{ args = { charte = charte, type = "titre" } }
     local couleurTexte = charteModule.couleur{ args = { charte = charte, type = "texte" } }
     local couleurTexte = charteModule.couleur{ args = { charte = charte, type = "texte" } }
    local couleurHR = charteModule.couleur{ args = { charte = charte, type = "hr" } }
    for i = 1, 5 do
        local titre = args["TitreOrdre" .. i]
        local mandat = args["MandatOrdre" .. i]
        local predecesseur = args["PrédécesseurOrdre" .. i]
        local successeur = args["SuccesseurOrdre" .. i]
        if titre then
            local mandatBlock = ""
            if mandat and mandat ~= "" then
                mandatBlock = '<div style="font-weight: normal; font-size: 90%;">' .. mw.text.encode(mandat) .. '</div>'
            end


    local mandat = args["Mandat"]
            local bloc = '<div style="margin: 0.5em 0; overflow: hidden; font-size: 90%;">' ..
    local predecesseur = args["Prédécesseur"]
                '<div style="background-color: ' .. couleurFond .. '; color: ' .. couleurTexte .. '; text-align: center; padding: 0.5em; font-weight: bold;">' ..
    local successeur = args["Successeur"]
                mw.text.encode(titre) .. mandatBlock ..
                '</div>' ..
                '<div style="display: flex; justify-content: space-between; align-items: center; padding: 0.5em;">'


    local html = {}
            if predecesseur and predecesseur ~= "" then
                bloc = bloc .. '<div style="text-align: left; flex: 1;">← [[' .. predecesseur .. ']]</div>'
            else
                bloc = bloc .. '<div style="text-align: left; flex: 1;"></div>'
            end


    table.insert(html, '<div style="margin: 5px; overflow: hidden; font-size: 90%;">')
            bloc = bloc .. '<div style="flex: 0 0 auto; padding: 0 1em;">·</div>'
    table.insert(html, '<div style="display: flex; justify-content: space-between; align-items: center; background-color: '
        .. couleurFond .. '; color: ' .. couleurTexte
        .. '; padding: 0.5em; font-weight: bold; text-align: center;">')


    -- Bloc gauche : prédécesseur
            if successeur and successeur ~= "" then
    if predecesseur and predecesseur ~= "" then
                bloc = bloc .. '<div style="text-align: right; flex: 1;">[[' .. successeur .. ']] </div>'
        table.insert(html, '<div style="flex: 1; text-align: center; font-size: 85%;">[[' .. predecesseur .. ']]</div>')
            else
    else
                bloc = bloc .. '<div style="text-align: right; flex: 1;"></div>'
        table.insert(html, '<div style="flex: 1;"></div>')
            end
    end
 
            bloc = bloc .. '</div></div>'


    -- Bloc central : titre + mandat
            bloc = bloc .. '<hr style="border: none; height: 1px; background-color: ' .. couleurHR .. ';">'
    table.insert(html, '<div style="flex: 2;">' .. mw.text.encode(titre))
    if mandat and mandat ~= "" then
        table.insert(html, '<div style="font-weight: normal; font-size: 90%;">' .. mw.text.encode(mandat) .. '</div>')
    end
    table.insert(html, '</div>')


    -- Bloc droit : successeur
            table.insert(result, bloc)
    if successeur and successeur ~= "" then
         end
        table.insert(html, '<div style="flex: 1; text-align: center; font-size: 85%;">[[' .. successeur .. ']] ▶</div>')
    else
         table.insert(html, '<div style="flex: 1;"></div>')
     end
     end


    table.insert(html, '</div></div>')
     return table.concat(result, "\n")
 
     return table.concat(html)
end
end


return p
return p

Version du 31 mai 2025 à 08:07

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

local p = {}
local charteModule = require("Module:Charte")  -- appel direct à ton module Charte

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

    -- Couleurs calculées une seule fois en dehors de la boucle
    local charte = args["Charte"] or "defaut"
    local couleurFond = charteModule.couleur{ args = { charte = charte, type = "titre" } }
    local couleurTexte = charteModule.couleur{ args = { charte = charte, type = "texte" } }
    local couleurHR = charteModule.couleur{ args = { charte = charte, type = "hr" } }

    for i = 1, 5 do
        local titre = args["TitreOrdre" .. i]
        local mandat = args["MandatOrdre" .. i]
        local predecesseur = args["PrédécesseurOrdre" .. i]
        local successeur = args["SuccesseurOrdre" .. i]

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

            local bloc = '<div style="margin: 0.5em 0; 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;">'

            if predecesseur and predecesseur ~= "" then
                bloc = bloc .. '<div style="text-align: left; flex: 1;">← [[' .. predecesseur .. ']]</div>'
            else
                bloc = bloc .. '<div style="text-align: left; flex: 1;"></div>'
            end

            bloc = bloc .. '<div style="flex: 0 0 auto; padding: 0 1em;">·</div>'

            if successeur and successeur ~= "" then
                bloc = bloc .. '<div style="text-align: right; flex: 1;">[[' .. successeur .. ']] →</div>'
            else
                bloc = bloc .. '<div style="text-align: right; flex: 1;"></div>'
            end

            bloc = bloc .. '</div></div>'

            bloc = bloc .. '<hr style="border: none; height: 1px; background-color: ' .. couleurHR .. ';">'

            table.insert(result, bloc)
        end
    end

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

return p