Módulo:Lista elementos

Permanently protected module
Origem: Wikipédia, a enciclopédia livre.
Documentação do módulo[ver] [editar] [histórico] [purgar]

Descrição

Este módulo implementa a predefinição {{Lista elementos}}, para formatar uma lista horizontal com um separador espaço estrela espaço padrão.

Uso

Outra documentação:

local z = {}

function z.main(frame)

    local args = frame:getParent().args
    local trimFunc = mw.text.trim -- proteção e acesso global

    local function getParam(name, default)
        if args[name] ~= nil and args[name] ~= '' then
            return args[name]
        else
            return default -- nil se não informado
        end
    end

    local paramSep = getParam('separador', getParam('sep', '·'))
    local spaces = tonumber(getParam('espaços', '1'))
    local glue

    if paramSep == ',' then
        glue = ', '
    elseif mw.text.unstripNoWiki(paramSep) == ' ' or paramSep == ' ' then -- {{space}}
        if spaces == 0 then
            glue = ''
        else
            glue = string.rep('\194\160', spaces - 1) .. paramSep
        end
    elseif paramSep == ' ' or paramSep == ' ' then
        glue = string.rep(paramSep, spaces)
    elseif paramSep == '2·' or paramSep == '·2' then
        -- '\194\160' é um espaço indivisivel (code UTF-8 sobre dois bites)
        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 class="sep-list">·</span>'
        elseif paramSep == '-' then
            paramSep = '–' -- tirar sep barra
        end
        if spaces == 0 then
            glue = paramSep
        else
            glue = string.rep('\194\160', spaces) .. paramSep .. string.rep('\194\160', spaces - 1) .. ' '
        end
    end

    local secable = (args['divisível'] == 'sim')
    local items = {}

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

    return table.concat(items, glue)
end

return z