Moduł:Spis

Z Wikiźródeł, wolnej biblioteki

Generuje kod dla Szablonu {{SpisPozycja}}. Kod pochodzi ze źródeł fr fr:Module:Table.


-- Kod pochodzi ze żródeł fr - https://fr.wikisource.org/wiki/Module:Table
-- Szablon jest w trakcie modyfikacji...
-- Code dérivé des modèles table et table2 par Verdy_p et Faager, toute divergence dans le code ou le comportement est un bug.
function table( frame )

    local args = frame.args

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

     -- Conteneur général (relatif, et à fond non transparent) de positionnement de la table 
    local text = string.format( '<div class="tableItem" style="position:relative;margin:%s auto;',
                                 out_arg( args.espace, ".125em" ) )
    if args.align == 'left' or args.align == 'right' then
        text = text .. string.format('margin-%s:0;', args.align)
    end

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

    if args.bgcolor and args.bgcolor ~= '' then
        text = text .. string.format('background:%s;', args.bgcolor)
    elseif not_nodots then
        text = text .. 'background:#FFFFFF;'
    end

    if args.color and args.color ~= '' then
        text = text .. string.format('color:%s;', args.color)
    elseif not_nodots then
        text = text .. 'color:#000000;'
    end

    -- zoom pour forcer hasLayout (bogue IE6 des marges)
    text = text .. 'line-height:normal;zoom:1">' -- Fin de l'ouverture du div externe

    -- TDM : Conteneur avec section+titre+page (seulement nécessaire si numéro de page)
    if args.page and args.page ~= '' then
        text = text .. string.format( '<div style="margin-right:%spx">', out_arg( args.widthp, "0" ) )
        -- GAUCHE+CENTRE: Conteneur flottant à gauche avec section+titre (seulement nécessaire si numéro de page)
        -- oryginalnie <div style="float:left;width:100%"> - usunieto float:left ze względu na problemy wyśw. epub
        text = text .. '<div style="width:100%">'
    end

    -- GAUCHE: Conteneur flottant à gauche du numéro de section (non transparent si pointillés)
    if args.sekcja and args.sekcja ~= '' 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.widths, 45), out_arg( args.aligns, 'right') )

        if not_nodots then
            text = text .. string.format('<span style="background:%s">', out_arg( args.bgcolor, '#FFFFFF' ) )
        end
        text = text .. args.sekcja .. '&nbsp;'
        if not_nodots then
            text = text .. '</span>'
        end
        text = text .. '</div>'

        -- CENTRE: Conteneur du titre et des pointillés 
        text = text .. string.format( '<div style="position:relative;margin-left:%spx">', out_arg(args.widths, 45) )
    end

    -- Conteneur interne optionnel pour gérer la marge d’indentation négative
    if tonumber( out_arg(args.wciecie, 0 ) ) < 0 then
        text = text .. string.format( '<div style="margin-left:%s%s;text-indent:%s%s">',
                                      -args.wciecie, out_arg(args.wciecie_jedn, "em"), args.wciecie, out_arg(args.wciecie_jedn, "em" ) )
    end

    -- Le titre lui-même (justifiable, indentable), en haut du conteneur CENTRE (non transparent si pointillés)
    text = text .. '<div style="position:relative;z-index:2;'
    text = text .. string.format( 'text-align:%s;', out_arg( args.text_align, 'justify' ) )
    if tonumber( out_arg(args.wciecie, 0 ) ) > 0 then
        text = text .. string.format( 'text-indent:%s%s', args.wciecie, out_arg(args.wciecie_jedn, "em" ) )
    end
    text = text .. '">'
    if not_nodots then
         text = text .. string.format('<span style="background:%s">', out_arg( args.bgcolor, '#FFFFFF' ) )
    end
    text = text .. out_arg(args.tyt, '' )
    if not_nodots then
        text = text .. '&nbsp;</span>'
    end
    text = text .. '</div>'

    -- Fin du conteneur interne optionnel pour gérer la marge d’indentation négative
    if tonumber( out_arg(args.wciecie, 0 ) ) < 0 then
        text = text  .. '</div>'
    end

    -- Les pointillés éventuels (superposés en bas, nécessite un positionnement absolu dans le conteneur CENTRE)
    if not_nodots then
        text = text .. '<div style="position:relative;'
        text = text .. string.format( 'margin-left:%d%s">', math.abs( tonumber( out_arg( args.wciecie, "0" ) ) ) + 1, out_arg( args.wciecie_jedn, "em" ) )
        text = text .. '<div style="position:absolute;z-index:1;bottom:.3em;width:100%;border-bottom:0.135em '
        if args.dashed then
        	text = text .. 'dashed '
        else
        	text = text .. 'dotted '
        end
        text = text .. out_arg( args.color, '#000000' ) .. '"></div>'
        text = text .. '</div>'
    end

    -- CENTRE: Fin du conteneur du titre et des pointillés
    if args.sekcja and args.sekcja ~= '' then
        text = text .. '</div>'
        -- Étend le flottant à gauche verticalement (le numéro de section)
        text = text .. '<div style="clear:both"></div>'
    end

    if args.page and args.page ~= '' then
        -- GAUCHE+CENTRE: Fin du conteneur avec section+titre (seulement nécessaire si numéro de page)
        text = text .. '</div>'
        -- DROITE: Conteneur flottant à droite du numéro de page (seulement nécessaire si numéro de page)
        text = text .. '<div style="float:right">'
        -- Le numéro, insécable, est positionné verticalement en bas dans le flottant (non transparent si pointillés)
        text = text .. '<div style="position:absolute;z-index:2;bottom:0;right:0;text-indent:0;white-space:nowrap;'
        if args.widthp and args.widthp ~= '' and args.page_align and args.page_align ~= '' then
            text = text .. string.format( 'text-align:%s;width:%spx;">', args.page_align, args.widthp )
        else
            text = text .. 'text-align:right">'
        end
        if not_nodots then
            text = text .. string.format('<span style="background:%s">', out_arg( args.bgcolor, '#FFFFFF' ) )
            -- seulement pour éviter de coller aux pointillés
            text = text .. '&nbsp;'
        end
        text = text .. args.page
        if not_nodots then
            text = text .. '</span>'
        end
        text = text .. '</div>'
        -- DROITE: Fin du conteneur du flottant du numéro de page (seulement nécessaire si numéro de page)
        text = text .. '</div>'

        -- Étend le flottant à droite verticalement (pour descendre le numéro de page)
        text = text .. '<div style="clear:both"></div>'

        -- TDM :Fin du conteneur avec section+titre+page (seulement nécessaire si numéro de page)
        text = text .. '</div>'
    end

    -- EXTERNE: Fin du conteneur
    text = text .. '</div>'

    return text
end

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

local p = {}

-- Aide au debuggage, retourne le code généré sous forme d'une chaîne de caractères encodé
-- et sous forme de html.
function p.table_as_string( frame )
    return mw.text.encode( table( frame ) ) .. '<div style="clear:both"></div>' .. table( frame )
end

function p.table_direct( frame )
    return table( frame )
end
 
function p.table( frame )
    return table( frame:getParent() )
end
 
return p