Module:Lista piéces

De Vouiquipèdia, l’enciclopèdia abada.

La documentation pour ce module peut être créée à Module:Lista piéces/doc

local z = {}

function z.main(frame)

    local args = frame:getParent().args
    local trimFunc = mw.text.trim -- cache accès gllobâl

    local function getParam(name, default)
        if args[name] ~= nil and args[name] ~= '' then
            return args[name]
        else
            return default -- nil se pas spècefiâ
        end
    end

    local paramSep = getParam('sèparator', getParam('sèp', '·'))
    local espacos = tonumber(getParam('èspâços', '1'))
    local glue

    if paramSep == ',' then
        glue = ', '
    elseif mw.text.unstripNoWiki(paramSep) == ' ' or paramSep == ' ' then -- {{èspâço}},  
        glue = paramSep
    elseif paramSep == '2·' or paramSep == '·2' then
        -- '\194\160' est un èspâço pas sècâblo (code UTF-8 sur doux octèts)
        glue = '\194\160\194\160<span style="font-weight:bold">·</span>\194\160 '
    elseif paramSep == '2•' or paramSep == '•2' then
        glue = '\194\160\194\160\194\160 '
    else
        if paramSep == '·' then
            paramSep = '<span style="font-weight:bold">·</span>'
        elseif paramSep == '-' or paramSep == '−' then
            paramSep = '–' -- terèt mié-cadratin
        elseif paramSep == '--' then
            paramSep = '—' -- terèt cadratin
        end
        if espacos == 0 then
            glue = paramSep
        else
            glue = string.rep('\194\160', espacos) .. paramSep .. string.rep('\194\160', espacos-1) .. ' '
        end
    end

    local secablo = (args['sècâblo'] == 'ouè')
    local items = {}

    for i,v in ipairs(args) do
        local item = trimFunc(v)
        if item ~= '' then
            if not secablo then
                item = '<span class="nowrap">'..item..'</span>'
            end
            items[#items+1] = item
        end
    end

    return table.concat(items, glue)
end

return z