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évoqué
Ligne 1 : Ligne 1 :
local p = {}
local p = {}
local charteModule = require("Module:Charte") -- appel direct à ton module Charte
local charteModule = require("Module:Charte")


function p.multipleSuccession(frame)
function p.successionUnique(frame)
     local args = frame.args
     local args = frame.args
     local result = {}
     local titre = args["Titre"]
    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 mandat = args["Mandat"]
        local titre = args["TitreOrdre" .. i]
    local predecesseur = args["Prédécesseur"]
        local mandat = args["MandatOrdre" .. i]
    local successeur = args["Successeur"]
        local predecesseur = args["PrédécesseurOrdre" .. i]
        local successeur = args["SuccesseurOrdre" .. i]


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


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


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


            bloc = bloc .. '<div style="flex: 0 0 auto; padding: 0 1em;">·</div>'
    -- Bloc central : titre + mandat
    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>')


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


            bloc = bloc .. '</div>'
    table.insert(html, '</div></div>')
 
            bloc = bloc .. '<hr style="border: none; height: 1px; background-color: ' .. couleurHR .. ';">'
 
            table.insert(result, bloc)
        end
    end


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


return p
return p

Version du 31 mai 2025 à 08:00

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

local p = {}
local charteModule = require("Module:Charte")

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

    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 mandat = args["Mandat"]
    local predecesseur = args["Prédécesseur"]
    local successeur = args["Successeur"]

    local html = {}

    table.insert(html, '<div style="margin: 5px; overflow: hidden; font-size: 90%;">')
    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 predecesseur and predecesseur ~= "" then
        table.insert(html, '<div style="flex: 1; text-align: center; font-size: 85%;">◀ [[' .. predecesseur .. ']]</div>')
    else
        table.insert(html, '<div style="flex: 1;"></div>')
    end

    -- Bloc central : titre + mandat
    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
    if successeur and successeur ~= "" then
        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

    table.insert(html, '</div></div>')

    return table.concat(html)
end

return p