Módulo:Tabela

Wikisource, a biblioteca livre
Documentação do módulo[ver] [editar] [histórico] [purgar]

Uso[editar]

Implementa a predefinição {{tabela}}.

-- Adaptação de [[:fr:Modèle:Table]], derivado dos modelos table e table2 de Verdy_p e Faager
function tabela( frame )

    local args = frame.args

    local not_nodots = args[1] == nil or mw.text.trim( args[1] ) ~= 'nodots'

     -- Recipiente geral (relativo e com fundo não transparente) para posicionar a mesa 
    local text = string.format( '<div class="tableItem" style="position:relative;margin:%s auto;',
                                 out_arg( args["espaço"], ".125em" ) )
    if args.align == 'left' or args.align == 'right' then
        text = text .. string.format('margin-%s:0;', args.align)
    end

    if args["largura"] and args["largura"] ~= '' then
        text = text .. string.format('max-width:%s;', args["largura"])
    end

    if args["cor-fundo"] and args["cor-fundo"] ~= '' then
        text = text .. string.format('background:%s;', args["cor-fundo"])
    elseif not_nodots then
        text = text .. 'background:#FFF;'
    end

    if args["cor"] and args["cor"] ~= '' then
        text = text .. string.format('color:%s;', args["cor"])
    elseif not_nodots then
    	-- a cor padrão é aquele herdado
        -- text = text .. 'color:#000;'
    end

    text = text .. 'line-height:normal">' -- Fin de l'ouverture du div externe

    -- Tab. de conteúdo: Container com seção + título + página (apenas necessário se houver número da página)
    if args["página"] and args["página"] ~= '' then
        text = text .. string.format( '<div style="margin-right:%spx">', out_arg( args["largura-p"], "0" ) )
        -- GAUCHE+CENTRE: Conteneur flottant à gauche avec section+titre (seulement nécessaire si numéro de page)
        text = text .. '<div style="float:left;width:100%">'
    end

    -- ESQUERDA: Recipiente flutuante à esquerda do número da seção (não transparente se pontilhado)
    if args["seção"] and args["seção"] ~= '' then
        text = text .. string.format( '<div style="float:left; z-index:2; min-width:%spx; text-indent:0; text-align:%s; white-space:nowrap">',
                                      out_arg( args["largura-s"], 45), out_arg( args["alinhamento-s"], 'right') )

        if not_nodots then
            text = text .. string.format('<span style="background:%s">', out_arg( args["cor-fundo"], '#FFF' ) )
        end
        text = text .. args["seção"] .. '&nbsp;'
        if not_nodots then
            text = text .. '</span>'
        end
        text = text .. '</div>'

        -- CENTRO: Container de títulos e linhas pontilhadas
        text = text .. string.format( '<div style="position:relative;margin-left:%spx">', out_arg(args["largura-s"], 45) )
    end

    -- Container interno opcional para gerenciar a margem de recuo negativo
    if tonumber( out_arg(args["indentação"], 0 ) ) < 0 then
        text = text .. string.format( '<div style="margin-left:%s%s;text-indent:%s%s">',
                                      -args["indentação"], out_arg(args["identação-unidade"], "em"), args["indentação"], out_arg(args["identação-unidade"], "em" ) )
    end

    -- O título em si (justificável, indentificável), no topo do CENTRO do recipiente (não transparente se pontilhado)
    text = text .. '<div style="position:relative;z-index:2;'
    if args["alinhamento-texto"] then
        text = text .. string.format( 'text-align:%s;', args["alinhamento-texto"] )
    end
    if tonumber( out_arg(args["indentação"], 0 ) ) > 0 then
        text = text .. string.format( 'text-indent:%s%s', args["indentação"], out_arg(args["identação-unidade"], "em" ) )
    end
    text = text .. '">'
    if not_nodots then
         text = text .. string.format('<span style="background:%s">', out_arg( args["cor-fundo"], '#FFF' ) )
    end
    text = text .. out_arg(args["título"], '' )
    if not_nodots then
        text = text .. '&nbsp;</span>'
    end
    text = text .. '</div>'

    -- Fim do recipiente interno opcional para gerenciar a margem de indentação negativa
    if tonumber( out_arg(args["indentação"], 0 ) ) < 0 then
        text = text  .. '</div>'
    end

    -- Qualquer linha pontilhada (sobreposta na parte inferior, requer posicionamento absoluto no recipiente CENTRO)
    if not_nodots then
        text = text .. '<div class="ws-noexport" style="position:relative;'
        text = text .. string.format( 'margin-left:%d%s">', math.abs( tonumber( out_arg( args["indentação"], "0" ) ) ) + 1, out_arg( args["identação-unidade"], "em" ) )
        text = text .. '<div style="position:absolute;z-index:1;bottom:.3em;width:100%;border-bottom:0.135em dotted'
        -- La["cor"] par défaut pour les pointillés est celle héritée
        text = text .. out_arg( args["cor"], '' ) .. '"></div>'
        --text = text .. out_arg( args["cor"], ' #000' ) .. '"></div>'
        text = text .. '</div>'
    end

    -- CENTRO: Fim do recipiente do título e linhas pontilhadas
    if args["seção"] and args["seção"] ~= '' then
        text = text .. '</div>'
        -- Estende o flutuador esquerdo verticalmente (número de seção)
        text = text .. '<div style="clear:both"></div>'
    end

    if args["página"] and args["página"] ~= '' then
        -- ESQUERDA+CENTRO: Fim do recipiente com seção+título (somente necessário se o número da página)
        text = text .. '</div>'
        -- DIREITA: Recipiente flutuante à direita do número de página (somente necessário se o número de página)
        text = text .. '<div class="ws-noexport" style="float:right">'
        -- O número, inquebrável, é posicionado verticalmente na parte inferior do flutuador (não transparente se pontilhado).
        text = text .. '<div style="position:absolute; z-index:2; bottom:0; right:0; text-indent:0; text-align:right; white-space:nowrap">'
        if not_nodots then
            text = text .. string.format('<span style="background:%s">', out_arg( args["cor-fundo"], '#FFF' ) )
            -- seulement pour éviter de coller aux pointillés
            text = text .. '&nbsp;'
        end
        text = text .. args["página"]
        if not_nodots then
            text = text .. '</span>'
        end
        text = text .. '</div>'
        -- DIREITA: Fim do recipiente do flutuador do número de página (somente necessário se o número de página)
        text = text .. '</div>'

        -- Estende o flutuador para a direita na vertical (para baixar o número de página)
        text = text .. '<div style="clear:both"></div>'

        -- Tab. de conteúdo :Fim do recipiente com seção+título+página (somente necessário se o número da página)
        text = text .. '</div>'
    end

    -- EXTERNO: Fim do recipiente
    text = text .. '</div>'

    return text
end

function out_arg( arg, default )
    if arg and arg ~= '' then
        return arg
    end
    return default
end

local p = {}

-- Ajuda com a depuração, retorna o código gerado na forma de uma sequência de caracteres codificada
-- e na forma de html.
function p.table_as_string( frame )
    return mw.text.encode( tabela( frame ) ) .. '<div style="clear:both"></div>' .. tabela( frame )
end
 
function p.tabela( frame )
    return tabela( frame:getParent() )
end
 
return p