Module:Multiparamètres
De Wicri Jarville
Révision datée du 11 août 2017 à 14:58 par imported>Jacques Ducloy (1 révision importée)
La documentation pour ce module peut être créée à Module:Multiparamètres/doc
local p = {}
function p.brut(frame)
    return p._main(frame, function (item) return item end)
end
function p.lien(frame)
    return p._main(frame, function (item) return '[['..item..']]' end)
end
function p.categorie(frame)
    return p._main(frame, function (item) return '[[:Catégorie:'..item..'|'..item..']]' end)
end
function p.utilisateur(frame)
    return p._main(frame, function (item) return '[[Utilisateur:'..item..'|'..item..']]' end)
end
function p._main(frame, formatter)
    local args = frame:getParent().args
    local trimFunc = mw.text.trim -- cache accès global
    local gras = (args.gras and args.gras ~= '')
    local items = {}
    for i,v in ipairs(args) do
        local item = trimFunc(v)
        if item ~= '' then
            item = formatter(item)
            if gras then
                item = "'''" .. item .. "'''"
            end
            items[#items + 1] = item
        end
    end
    if #items == 0 then
        return ''
    elseif #items == 1 then
        return items[1]
    else
        -- le paramètre "et" peut être défini à vide, exemple : [[Modèle:Module biblio/responsabilité principale]]
        local dernierSeparateur = (args.et and args.et or 'et')
        return table.concat(items, ', ', 1, #items - 1) .. ' ' .. dernierSeparateur .. ' ' .. items[#items]
    end
end
return p

