Module:Aligned table: Difference between revisions
no edit summary
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
-- This module implements {{aligned table}} | -- This module implements {{aligned table}} | ||
local p = {} | local p = {} | ||
Line 18: | Line 17: | ||
colstyle[2] = 'text-align:right;' | colstyle[2] = 'text-align:right;' | ||
end | end | ||
-- create the root table | |||
local root = mw.html.create('table') | local root = mw.html.create('table') | ||
-- add table style for fullwidth | |||
if fullwidth ~= '' then | if fullwidth ~= '' then | ||
root | root | ||
Line 28: | Line 27: | ||
:css('border', 'none') | :css('border', 'none') | ||
end | end | ||
-- add table classes | |||
if class ~= '' then | if class ~= '' then | ||
root:addClass(class) | root:addClass(class) | ||
end | end | ||
-- add table style | |||
if style ~= '' then | if style ~= '' then | ||
root:cssText(style) | root:cssText(style) | ||
end | end | ||
-- build arrays with the column styles and classes | |||
for i = 1,cols do | for i = 1,cols do | ||
colclass[ i ] = colclass[ i ] or '' | colclass[ i ] = colclass[ i ] or '' | ||
Line 50: | Line 52: | ||
end | end | ||
end | end | ||
-- compute the maximum cell index | |||
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) | |||
end | |||
local cell = | end | ||
-- compute the number of rows | |||
local rows = math.ceil(cellcount / cols) | |||
-- build the table content | |||
for j=1,rows do | |||
-- start a new row | |||
local row = root:tag('tr') | |||
row:css('vertical-align', 'top') | |||
-- loop over the cells in each row | |||
for i=1,cols do | |||
local cell = row:tag('td') | |||
if args['class' .. tostring(j) .. '.' .. tostring(i)] then | if args['class' .. tostring(j) .. '.' .. tostring(i)] then | ||
cell:addClass(args['class' .. tostring(j) .. '.' .. tostring(i)]) | cell:addClass(args['class' .. tostring(j) .. '.' .. tostring(i)]) | ||
Line 70: | Line 84: | ||
cell:cssText(colstyle[i]) | cell:cssText(colstyle[i]) | ||
end | end | ||
cell:wikitext( | cell:wikitext(args[cols*(j - 1) + i] or '') | ||
end | end | ||
end | end | ||
-- return the root table | |||
return tostring(root) | return tostring(root) | ||
end | end | ||
return p | return p |