Ir para o conteúdo

Módulo:Aligned table: mudanças entre as edições

De Wiki TokuDrive
Importando predefinição/módulo da Wikipédia em português para manter layout
 
Importando predefinição/módulo da Wikipédia em português para manter layout
 
Linha 1: Linha 1:
-- Este módulo implementa a {{Aligned table}}
-- Este módulo implementa a predefinição {{Tabela alinhada}}
local p = {}
local p = {}


local function isnotempty(s)
local function isnotempty(s)
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
end
local function getarg(args, ...)
for i = 1, select('#', ...) do
local key = select(i, ...)
local value = args[key]
if isnotempty(value) then
return value
end
end
return nil
end
local function getpresentarg(args, ...)
for i = 1, select('#', ...) do
local key = select(i, ...)
if args[key] ~= nil then
return args[key]
end
end
return nil
end
end


Linha 11: Linha 32:
local colclass = {}
local colclass = {}
local colstyle = {}
local colstyle = {}
local cols = tonumber(args['cols']) or 2
local cols = tonumber(getarg(args, 'cols', 'colunas')) or 2


-- cria a tabela raiz
-- cria a tabela raiz
Linha 17: Linha 38:


-- adiciona estilo de tabela para largura total
-- adiciona estilo de tabela para largura total
if isnotempty(args['fullwidth']) then
if getarg(args, 'fullwidth', 'largura total') then
root
root
:css('width', '100%')
:css('width', '100%')
Linha 26: Linha 47:


-- adiciona classes de tabela
-- adiciona classes de tabela
if isnotempty(args['class']) then
local tableclass = getarg(args, 'class', 'classe')
root:addClass(args['class'])
if tableclass then
root:addClass(tableclass)
end
end


-- adiciona estilo de tabela
-- adiciona estilo de tabela
if isnotempty(args['style']) then
local tablestyle = getarg(args, 'style', 'estilo')
root:cssText(args['style'])
if tablestyle then
root:cssText(tablestyle)
end
end


-- constrói arranjos com os estilos e classes das colunas
-- constrói arranjos com os estilos e classes das colunas
if isnotempty(args['leftright']) then
if getarg(args, 'leftright', 'esquerda-direita') then
colstyle[1] = 'text-align:left;'
colstyle[1] = 'text-align:left;'
colstyle[2] = 'text-align:right;'
colstyle[2] = 'text-align:right;'
end
end
if isnotempty(args['rightleft']) then
if getarg(args, 'rightleft', 'direita-esquerda') then
colstyle[1] = 'text-align:right;'
colstyle[1] = 'text-align:right;'
colstyle[2] = 'text-align:left;'
colstyle[2] = 'text-align:left;'
end
end
for i = 1,cols do
for i = 1,cols do
colclass[ i ] = colclass[ i ] or ''
local n = tostring(i)
colstyle[ i ] = colstyle[ i ] or ''
colclass[i] = colclass[i] or ''
if isnotempty(args['colstyle']) then
colstyle[i] = colstyle[i] or ''
colstyle[ i ] = args['colstyle'] .. ';' .. colstyle[ i ]
 
local commoncolstyle = getarg(args, 'colstyle', 'estilo das colunas')
if commoncolstyle then
colstyle[i] = commoncolstyle .. ';' .. colstyle[i]
end
end
if isnotempty(args['colalign' .. tostring(i)]) then
 
colstyle[ i ] = 'text-align:' .. args['colalign' .. tostring(i)] .. ';' .. colstyle[ i ]
local colalign = getarg(
elseif isnotempty(args['col' .. tostring(i) .. 'align']) then
args,
colstyle[ i ] = 'text-align:' .. args['col' .. tostring(i) .. 'align'] .. ';' .. colstyle[ i ]
'colalign' .. n,
elseif isnotempty(args['align' .. tostring(i)]) then
'col' .. n .. 'align',
colstyle[ i ] = 'text-align:' .. args['align' .. tostring(i)] .. ';' .. colstyle[ i ]
'align' .. n,
'alinhamento da coluna ' .. n
)
if colalign then
colstyle[i] = 'text-align:' .. colalign .. ';' .. colstyle[i]
end
end
if isnotempty(args['colnowrap' .. tostring(i)]) then
 
colstyle[ i ] = 'white-space:nowrap;' .. colstyle[ i ]
if getarg(
elseif isnotempty(args['col' .. tostring(i) .. 'nowrap']) then
args,
colstyle[ i ] = 'white-space:nowrap;' .. colstyle[ i ]
'colnowrap' .. n,
elseif isnotempty(args['nowrap' .. tostring(i)]) then
'col' .. n .. 'nowrap',
colstyle[ i ] = 'white-space:nowrap;' .. colstyle[ i ]
'nowrap' .. n,
'sem quebra na coluna ' .. n
) then
colstyle[i] = 'white-space:nowrap;' .. colstyle[i]
end
end
if isnotempty(args['colwidth' .. tostring(i)]) then
 
colstyle[ i ] = 'width:' .. args['colwidth' .. tostring(i)] .. ';' .. colstyle[ i ]
local colwidth = getarg(
elseif isnotempty(args['col' .. tostring(i) .. 'width']) then
args,
colstyle[ i ] = 'width:' .. args['col' .. tostring(i) .. 'width'] .. ';' .. colstyle[ i ]
'colwidth' .. n,
elseif isnotempty(args['colwidth']) then
'col' .. n .. 'width',
colstyle[ i ] = 'width:' .. args['colwidth'] .. ';' .. colstyle[ i ]
'largura da coluna ' .. n
)
if colwidth then
colstyle[i] = 'width:' .. colwidth .. ';' .. colstyle[i]
else
local commoncolwidth = getarg(args, 'colwidth', 'largura das colunas')
if commoncolwidth then
colstyle[i] = 'width:' .. commoncolwidth .. ';' .. colstyle[i]
end
end
end
if isnotempty(args['colstyle' .. tostring(i)]) then
 
colstyle[ i ] = colstyle[ i ] .. args['colstyle' .. tostring(i)]
local specificcolstyle = getarg(
elseif isnotempty(args['col' .. tostring(i) .. 'style']) then
args,
colstyle[ i ] = colstyle[ i ] .. args['col' .. tostring(i) .. 'style']
'colstyle' .. n,
elseif isnotempty(args['style' .. tostring(i)]) then
'col' .. n .. 'style',
colstyle[ i ] = colstyle[ i ] .. args['style' .. tostring(i)]
'style' .. n,
'estilo da coluna ' .. n
)
if specificcolstyle then
colstyle[i] = colstyle[i] .. specificcolstyle
end
end
if isnotempty(args['colclass' .. tostring(i)]) then
 
colclass[ i ] =  args['colclass' .. tostring(i)]
local specificcolclass = getarg(
elseif isnotempty(args['col' .. tostring(i) .. 'class']) then
args,
colclass[ i ] =  args['col' .. tostring(i) .. 'class']
'colclass' .. n,
elseif isnotempty(args['class' .. tostring(i)]) then
'col' .. n .. 'class',
colclass[ i ] = args['class' .. tostring(i)]
'class' .. n,
'classe da coluna ' .. n
)
if specificcolclass then
colclass[i] = specificcolclass
end
end
end
end
-- calcula o índice máximo da célula
-- calcula o índice máximo da célula
local cellcount = 0
local cellcount = 0
for k, v in pairs( args ) do
for k, v in pairs(args) do
if type( k ) == 'number' then
if type(k) == 'number' then
cellcount = math.max(cellcount, k)
cellcount = math.max(cellcount, k)
end
end
end
end
-- calcula o número de linhas
-- calcula o número de linhas
local rows = math.ceil(cellcount / cols)
local rows = math.ceil(cellcount / cols)


-- constrói o conteúdo da tabela
-- constrói o conteúdo da tabela
if isnotempty(args['title']) then
local title = getarg(args, 'title', 'título')
if title then
local caption = root:tag('caption')
local caption = root:tag('caption')
caption:cssText(args['titlestyle'])
caption:cssText(getarg(args, 'titlestyle', 'estilo do título'))
caption:wikitext(args['title'])
caption:wikitext(title)
end
end
if isnotempty(args['above']) then
 
local above = getarg(args, 'above', 'cabeçalho superior')
if above then
local row = root:tag('tr')
local row = root:tag('tr')
local cell = row:tag('th')
local cell = row:tag('th')
cell:attr('colspan', cols)
cell:attr('colspan', cols)
cell:cssText(args['abovestyle'])
cell:cssText(getarg(args, 'abovestyle', 'estilo do cabeçalho superior'))
cell:wikitext(args['above'])
cell:wikitext(above)
end
end
for j=1,rows do
 
for j = 1,rows do
local rownumber = tostring(j)
 
-- inicia uma nova linha
-- inicia uma nova linha
local row = root:tag('tr')
local row = root:tag('tr')
if isnotempty(args['rowstyle']) then
local commonrowstyle = getarg(args, 'rowstyle', 'estilo das linhas')
row:cssText(args['rowstyle'])
if commonrowstyle then
row:cssText(commonrowstyle)
else
else
row:css('vertical-align', 'top')
row:css('vertical-align', 'top')
end
end
if isnotempty(args['rowclass']) then
 
row:addClass(args['rowclass'])
local commonrowclass = getarg(args, 'rowclass', 'classe das linhas')
if commonrowclass then
row:addClass(commonrowclass)
end
end
-- faz um loop nas células da linha
-- faz um loop nas células da linha
for i=1,cols do
for i = 1,cols do
local columnnumber = tostring(i)
local cell
local cell
if isnotempty(args['row' .. tostring(j) .. 'header']) then
 
if getarg(
args,
'row' .. rownumber .. 'header',
'cabeçalho da linha ' .. rownumber
) then
cell = row:tag('th'):attr('scope','col')
cell = row:tag('th'):attr('scope','col')
elseif isnotempty(args['col' .. tostring(i) .. 'header']) then
elseif getarg(
args,
'col' .. columnnumber .. 'header',
'cabeçalho da coluna ' .. columnnumber
) then
cell = row:tag('th'):attr('scope','row')
cell = row:tag('th'):attr('scope','row')
else
else
cell = row:tag('td')
cell = row:tag('td')
end
end
if args['class' .. tostring(j) .. '.' .. tostring(i)] then
 
cell:addClass(args['class' .. tostring(j) .. '.' .. tostring(i)])
local cellclass = getpresentarg(
args,
'class' .. rownumber .. '.' .. columnnumber,
'classe da célula ' .. rownumber .. '.' .. columnnumber
)
 
if cellclass ~= nil then
cell:addClass(cellclass)
else
else
if args['rowclass' .. tostring(j)] then
local specificrowclass = getpresentarg(
cell:addClass(args['rowclass' .. tostring(j)])
args,
elseif args['row' .. tostring(j) .. 'class'] then
'rowclass' .. rownumber,
cell:addClass(args['row' .. tostring(j) .. 'class'])
'row' .. rownumber .. 'class',
elseif args['rowevenclass'] and math.fmod(j,2) == 0 then
'classe da linha ' .. rownumber
cell:addClass(args['rowevenclass'])
)
elseif args['rowoddclass'] and math.fmod(j,2) == 1 then
 
cell:addClass(args['rowoddclass'])
if specificrowclass ~= nil then
cell:addClass(specificrowclass)
else
local evenclass = getpresentarg(
args,
'rowevenclass',
'classe das linhas pares'
)
local oddclass = getpresentarg(
args,
'rowoddclass',
'classe das linhas ímpares'
)
 
if evenclass ~= nil and math.fmod(j,2) == 0 then
cell:addClass(evenclass)
elseif oddclass ~= nil and math.fmod(j,2) == 1 then
cell:addClass(oddclass)
end
end
end
if colclass[i] ~= '' then
if colclass[i] ~= '' then
cell:addClass(colclass[i])
cell:addClass(colclass[i])
end
end
end
end
if args['style' .. tostring(j) .. '.' .. tostring(i)] then
 
cell:cssText(args['style' .. tostring(j) .. '.' .. tostring(i)])
local cellstyle = getpresentarg(
args,
'style' .. rownumber .. '.' .. columnnumber,
'estilo da célula ' .. rownumber .. '.' .. columnnumber
)
 
if cellstyle ~= nil then
cell:cssText(cellstyle)
else
else
if args['rowstyle' .. tostring(j)] then
local specificrowstyle = getpresentarg(
cell:cssText(args['rowstyle' .. tostring(j)])
args,
elseif args['rowevenstyle'] and math.fmod(j,2) == 0 then
'rowstyle' .. rownumber,
cell:cssText(args['rowevenstyle'])
'estilo da linha ' .. rownumber
elseif args['rowoddstyle'] and math.fmod(j,2) == 1 then
)
cell:cssText(args['rowoddstyle'])
 
elseif args['row' .. tostring(j) .. 'style'] then
if specificrowstyle ~= nil then
cell:cssText(args['row' .. tostring(j) .. 'style'])
cell:cssText(specificrowstyle)
else
local evenstyle = getpresentarg(
args,
'rowevenstyle',
'estilo das linhas pares'
)
local oddstyle = getpresentarg(
args,
'rowoddstyle',
'estilo das linhas ímpares'
)
local alternativerowstyle = getpresentarg(
args,
'row' .. rownumber .. 'style'
)
 
if evenstyle ~= nil and math.fmod(j,2) == 0 then
cell:cssText(evenstyle)
elseif oddstyle ~= nil and math.fmod(j,2) == 1 then
cell:cssText(oddstyle)
elseif alternativerowstyle ~= nil then
cell:cssText(alternativerowstyle)
end
end
end
if isnotempty(colstyle[i]) then
if isnotempty(colstyle[i]) then
cell:cssText(colstyle[i])
cell:cssText(colstyle[i])
end
end
end
end
cell:wikitext(mw.ustring.gsub(args[cols*(j - 1) + i] or '', '^(.-)%s*$', '%1') or '')
 
cell:wikitext(mw.ustring.gsub(
args[cols*(j - 1) + i] or '',
'^(.-)%s*$',
'%1'
) or '')
end
end
end
end
-- retorna a tabela raiz
-- retorna a tabela raiz
return tostring(root)
return tostring(root)

Edição atual tal como às 04h59min de 27 de setembro de 2026

-- Este módulo implementa a predefinição {{#invoke:aligned table|table}} local p = {}

local function isnotempty(s) return s and s:match( '^%s*(.-)%s*$' ) ~= end

local function getarg(args, ...) for i = 1, select('#', ...) do local key = select(i, ...) local value = args[key] if isnotempty(value) then return value end end return nil end

local function getpresentarg(args, ...) for i = 1, select('#', ...) do local key = select(i, ...) if args[key] ~= nil then return args[key] end end return nil end

function p.table(frame) local args = (frame.args[3] ~= nil) and frame.args or frame:getParent().args local entries = {} local colclass = {} local colstyle = {} local cols = tonumber(getarg(args, 'cols', 'colunas')) or 2

-- cria a tabela raiz local root = mw.html.create('table')

-- adiciona estilo de tabela para largura total if getarg(args, 'fullwidth', 'largura total') then root :css('width', '100%') :css('border-collapse', 'collapse') :css('border-spacing', '0px 0px') :css('border', 'none') end

-- adiciona classes de tabela local tableclass = getarg(args, 'class', 'classe') if tableclass then root:addClass(tableclass) end

-- adiciona estilo de tabela local tablestyle = getarg(args, 'style', 'estilo') if tablestyle then root:cssText(tablestyle) end

-- constrói arranjos com os estilos e classes das colunas if getarg(args, 'leftright', 'esquerda-direita') then colstyle[1] = 'text-align:left;' colstyle[2] = 'text-align:right;' end if getarg(args, 'rightleft', 'direita-esquerda') then colstyle[1] = 'text-align:right;' colstyle[2] = 'text-align:left;' end for i = 1,cols do local n = tostring(i) colclass[i] = colclass[i] or colstyle[i] = colstyle[i] or

local commoncolstyle = getarg(args, 'colstyle', 'estilo das colunas') if commoncolstyle then colstyle[i] = commoncolstyle .. ';' .. colstyle[i] end

local colalign = getarg( args, 'colalign' .. n, 'col' .. n .. 'align', 'align' .. n, 'alinhamento da coluna ' .. n ) if colalign then colstyle[i] = 'text-align:' .. colalign .. ';' .. colstyle[i] end

if getarg( args, 'colnowrap' .. n, 'col' .. n .. 'nowrap', 'nowrap' .. n, 'sem quebra na coluna ' .. n ) then colstyle[i] = 'white-space:nowrap;' .. colstyle[i] end

local colwidth = getarg( args, 'colwidth' .. n, 'col' .. n .. 'width', 'largura da coluna ' .. n ) if colwidth then colstyle[i] = 'width:' .. colwidth .. ';' .. colstyle[i] else local commoncolwidth = getarg(args, 'colwidth', 'largura das colunas') if commoncolwidth then colstyle[i] = 'width:' .. commoncolwidth .. ';' .. colstyle[i] end end

local specificcolstyle = getarg( args, 'colstyle' .. n, 'col' .. n .. 'style', 'style' .. n, 'estilo da coluna ' .. n ) if specificcolstyle then colstyle[i] = colstyle[i] .. specificcolstyle end

local specificcolclass = getarg( args, 'colclass' .. n, 'col' .. n .. 'class', 'class' .. n, 'classe da coluna ' .. n ) if specificcolclass then colclass[i] = specificcolclass end end

-- calcula o índice máximo da célula local cellcount = 0 for k, v in pairs(args) do if type(k) == 'number' then cellcount = math.max(cellcount, k) end end

-- calcula o número de linhas local rows = math.ceil(cellcount / cols)

-- constrói o conteúdo da tabela local title = getarg(args, 'title', 'título') if title then local caption = root:tag('caption') caption:cssText(getarg(args, 'titlestyle', 'estilo do título')) caption:wikitext(title) end

local above = getarg(args, 'above', 'cabeçalho superior') if above then local row = root:tag('tr') local cell = row:tag('th') cell:attr('colspan', cols) cell:cssText(getarg(args, 'abovestyle', 'estilo do cabeçalho superior')) cell:wikitext(above) end

for j = 1,rows do local rownumber = tostring(j)

-- inicia uma nova linha local row = root:tag('tr') local commonrowstyle = getarg(args, 'rowstyle', 'estilo das linhas') if commonrowstyle then row:cssText(commonrowstyle) else row:css('vertical-align', 'top') end

local commonrowclass = getarg(args, 'rowclass', 'classe das linhas') if commonrowclass then row:addClass(commonrowclass) end

-- faz um loop nas células da linha for i = 1,cols do local columnnumber = tostring(i) local cell

if getarg( args, 'row' .. rownumber .. 'header', 'cabeçalho da linha ' .. rownumber ) then cell = row:tag('th'):attr('scope','col') elseif getarg( args, 'col' .. columnnumber .. 'header', 'cabeçalho da coluna ' .. columnnumber ) then cell = row:tag('th'):attr('scope','row') else cell = row:tag('td') end

local cellclass = getpresentarg( args, 'class' .. rownumber .. '.' .. columnnumber, 'classe da célula ' .. rownumber .. '.' .. columnnumber )

if cellclass ~= nil then cell:addClass(cellclass) else local specificrowclass = getpresentarg( args, 'rowclass' .. rownumber, 'row' .. rownumber .. 'class', 'classe da linha ' .. rownumber )

if specificrowclass ~= nil then cell:addClass(specificrowclass) else local evenclass = getpresentarg( args, 'rowevenclass', 'classe das linhas pares' ) local oddclass = getpresentarg( args, 'rowoddclass', 'classe das linhas ímpares' )

if evenclass ~= nil and math.fmod(j,2) == 0 then cell:addClass(evenclass) elseif oddclass ~= nil and math.fmod(j,2) == 1 then cell:addClass(oddclass) end end

if colclass[i] ~= then cell:addClass(colclass[i]) end end

local cellstyle = getpresentarg( args, 'style' .. rownumber .. '.' .. columnnumber, 'estilo da célula ' .. rownumber .. '.' .. columnnumber )

if cellstyle ~= nil then cell:cssText(cellstyle) else local specificrowstyle = getpresentarg( args, 'rowstyle' .. rownumber, 'estilo da linha ' .. rownumber )

if specificrowstyle ~= nil then cell:cssText(specificrowstyle) else local evenstyle = getpresentarg( args, 'rowevenstyle', 'estilo das linhas pares' ) local oddstyle = getpresentarg( args, 'rowoddstyle', 'estilo das linhas ímpares' ) local alternativerowstyle = getpresentarg( args, 'row' .. rownumber .. 'style' )

if evenstyle ~= nil and math.fmod(j,2) == 0 then cell:cssText(evenstyle) elseif oddstyle ~= nil and math.fmod(j,2) == 1 then cell:cssText(oddstyle) elseif alternativerowstyle ~= nil then cell:cssText(alternativerowstyle) end end

if isnotempty(colstyle[i]) then cell:cssText(colstyle[i]) end end

cell:wikitext(mw.ustring.gsub( args[cols*(j - 1) + i] or , '^(.-)%s*$', '%1' ) or ) end end

-- retorna a tabela raiz return tostring(root) end

return p