« Module:Liste éléments » : différence entre les versions

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
retouche indentation, simplification paramètre sécable, optimisation boucle en n'utilisant pas ipairs()
0x010D (discussion | contributions)
quelque chose ne fonctionne pas, STOP BUTTON
Ligne 27 : Ligne 27 :
         glue = paramSep
         glue = paramSep
     elseif paramSep == '2·' or paramSep == '·2' then
     elseif paramSep == '2·' or paramSep == '·2' then
        -- '\194\160' est une espace insécable (code UTF-8 sur deux octets)
    -- '\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 '
         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
Ligne 46 : Ligne 46 :
     end
     end


     local secable = (args['sécable'] == 'oui')
     local secable = false
    if args['sécable'] == 'oui' then secable = true end


     for i=1,#args do
     for i,v in ipairs(args) do
         local value = mw.text.trim(args[i])
         local value = mw.text.trim(v)
         if value ~= '' then
         if value ~= '' then
             if not secable then value = '<span class="nowrap">'..value..'</span>' end
             if not secable then value = '<span class="nowrap">'..value..'</span>' end

Version du 10 mai 2016 à 06:28

local z = {}

function z.main(frame)

   local args = frame:getParent().args
   local paramSep, espaces, glue
   local values = {}
   if args['séparateur'] ~= nil and args['séparateur'] ~=  then
       paramSep = args['séparateur']
   elseif args['sép'] ~= nil and args['sép'] ~=  then
       paramSep = args['sép']
   else
       paramSep = '·'
   end
   if args['espaces'] ~= nil and args['espaces'] ~=  then
       espaces = tonumber(args['espaces'])
   else
       espaces = 1
   end
   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 = false
   if args['sécable'] == 'oui' then secable = true end
   for i,v in ipairs(args) do
       local value = mw.text.trim(v)
       if value ~=  then
           if not secable then value = ''..value..'' end
           values[#values+1] = value
       end
   end
   return table.concat(values, glue)

end

return z