« Module:Multiparamètres » : différence entre les versions
Aller à la navigation
Aller à la recherche
implémentation {{MultiParamètres-Lien}}, etc. |
hotfix |
||
Ligne 2 : | Ligne 2 : | ||
function p.brut(frame) | function p.brut(frame) | ||
return main(frame, '', '') | return p.main(frame, '', '') | ||
end | end | ||
function p.lien(frame) | function p.lien(frame) | ||
return main(frame, '[[', ']]') | return p.main(frame, '[[', ']]') | ||
end | end | ||
function p.categorie(frame) | function p.categorie(frame) | ||
return main(frame, '[[:Catégorie:', ']]') | return p.main(frame, '[[:Catégorie:', ']]') | ||
end | end | ||
function p.utilisateur(frame) | function p.utilisateur(frame) | ||
return main(frame, '[[Utilisateur:', ']]') | return p.main(frame, '[[Utilisateur:', ']]') | ||
end | end | ||
function p.main(frame, prefixe, suffixe) | |||
local args = frame:getParent().args | local args = frame:getParent().args |
Version du 7 janvier 2017 à 01:32
local p = {}
function p.brut(frame)
return p.main(frame, , )
end
function p.lien(frame)
return p.main(frame, '', '')
end
function p.categorie(frame)
return p.main(frame, 'Catégorie:', '')
end
function p.utilisateur(frame)
return p.main(frame, 'Utilisateur:', '')
end
function p.main(frame, prefixe, suffixe)
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 = prefixe .. item .. suffixe 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