« Module:Liste éléments » : différence entre les versions
Aller à la navigation
Aller à la recherche
rendons cela limpide |
m A changé le niveau de protection pour « Module:Liste éléments » ([Modifier=Autoriser uniquement les utilisateurs autopatrolled] (infini) [Renommer=Autoriser uniquement les administrateurs] (infini)) |
||
(11 versions intermédiaires par le même utilisateur non affichées) | |||
Ligne 4 : | Ligne 4 : | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local trimFunc = mw.text.trim -- cache accès global | |||
local | local function getParam(name, default) | ||
if args[name] ~= nil and args[name] ~= '' then | |||
return args[name] | |||
else | |||
return default -- nil si non spécifié | |||
end | |||
end | end | ||
local paramSep = getParam('séparateur', getParam('sép', '·')) | |||
local espaces = tonumber(getParam('espaces', '1')) | |||
local glue | |||
if paramSep == ',' then | if paramSep == ',' then | ||
Ligne 27 : | Ligne 23 : | ||
glue = paramSep | glue = paramSep | ||
elseif paramSep == '2·' or paramSep == '·2' then | elseif paramSep == '2·' or paramSep == '·2' then | ||
glue = ' | -- '\194\160' est une espace insécable (code UTF-8 sur deux octets) | ||
glue = '\194\160\194\160<span style="font-weight:bold">·</span>\194\160 ' | |||
elseif paramSep == '2•' or paramSep == '•2' then | elseif paramSep == '2•' or paramSep == '•2' then | ||
glue = ' | glue = '\194\160\194\160•\194\160 ' | ||
else | else | ||
if paramSep == '·' then | if paramSep == '·' then | ||
Ligne 41 : | Ligne 38 : | ||
glue = paramSep | glue = paramSep | ||
else | else | ||
glue = string.rep(' | glue = string.rep('\194\160', espaces) .. paramSep .. string.rep('\194\160', espaces-1) .. ' ' | ||
end | end | ||
end | end | ||
local secable = | local secable = (args['sécable'] == 'oui') | ||
local items = {} | |||
for i,v in ipairs(args) do | for i,v in ipairs(args) do | ||
local | local item = trimFunc(v) | ||
if | if item ~= '' then | ||
if not secable then | if not secable then | ||
item = '<span class="nowrap">'..item..'</span>' | |||
end | |||
items[#items+1] = item | |||
end | end | ||
end | end | ||
return table.concat( | return table.concat(items, glue) | ||
end | end | ||
return z | return z |
Dernière version du 17 mai 2017 à 13:45
local z = {}
function z.main(frame)
local args = frame:getParent().args local trimFunc = mw.text.trim -- cache accès global
local function getParam(name, default) if args[name] ~= nil and args[name] ~= then return args[name] else return default -- nil si non spécifié end end
local paramSep = getParam('séparateur', getParam('sép', '·')) local espaces = tonumber(getParam('espaces', '1')) local glue
if paramSep == ',' then glue = ', ' elseif mw.text.unstripNoWiki(paramSep) == ' ' or paramSep == ' ' then -- , glue = paramSep elseif paramSep == '2·' or paramSep == '·2' then -- '\194\160' est une espace insécable (code UTF-8 sur deux octets) glue = '\194\160\194\160·\194\160 ' elseif paramSep == '2•' or paramSep == '•2' then glue = '\194\160\194\160•\194\160 ' else if paramSep == '·' then paramSep = '·' elseif paramSep == '-' or paramSep == '−' then paramSep = '–' -- tiret demi-cadratin elseif paramSep == '--' then paramSep = '—' -- tiret cadratin end if espaces == 0 then glue = paramSep else glue = string.rep('\194\160', espaces) .. paramSep .. string.rep('\194\160', espaces-1) .. ' ' end end
local secable = (args['sécable'] == 'oui') local items = {}
for i,v in ipairs(args) do
local item = trimFunc(v)
if item ~= then
if not secable then
item = ''..item..''
end
items[#items+1] = item
end
end
return table.concat(items, glue)
end
return z