Module:Multiparamètres
De Nations.fr
Révision datée du 7 mars 2018 à 23:29 par fr>Od1n (dans ce cas, génère une seule espace au lieu de deux, toujours plus propre… et associé au diff précédent, code plus compréhensible)
La documentation pour ce module peut être créée à Module:Multiparamètres/doc
Erreur de script : Erreur Lua : erreur interne : l’interpréteur s’est arrêté avec le signal « -129 ».
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
local dernierSeparateur = args.et and ( ' ' .. args.et .. ' ' )
-- le paramètre "et" peut être défini à vide, exemple : [[Modèle:Module biblio/responsabilité principale]]
if args.et == '' then
dernierSeparateur = ' '
end
return mw.text.listToText( items, ', ', dernierSeparateur )
end
return p