Module:Aligned table: Difference between revisions
no edit summary
No edit summary |
No edit summary |
||
Line 18: | Line 18: | ||
colstyle[2] = 'text-align:right;' | colstyle[2] = 'text-align:right;' | ||
end | end | ||
local root = mw.html.create('table') | local root = mw.html.create('table') | ||
if fullwidth ~= '' then | if fullwidth ~= '' then | ||
root | root | ||
Line 28: | Line 28: | ||
:css('border', 'none') | :css('border', 'none') | ||
end | end | ||
if class ~= '' then | if class ~= '' then | ||
root:addClass(class) | root:addClass(class) | ||
end | end | ||
if style ~= '' then | if style ~= '' then | ||
root:cssText(style) | root:cssText(style) | ||
end | end | ||
for i = 1,cols do | for i = 1,cols do | ||
colclass[ i ] = colclass[ i ] or '' | colclass[ i ] = colclass[ i ] or '' | ||
Line 53: | Line 50: | ||
end | end | ||
end | end | ||
for k, v in pairs( args ) do | for k, v in pairs( args ) do | ||
if type( k ) == 'number' then | if type( k ) == 'number' then | ||
i = math.fmod(k-1,cols) + 1 | |||
local j = (k - i) / cols + 1 | |||
local cell = mw.html.create('td') | |||
local cell = | |||
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 85: | Line 70: | ||
cell:cssText(colstyle[i]) | cell:cssText(colstyle[i]) | ||
end | end | ||
cell:wikitext( | cell:wikitext(v) | ||
entries[ k ] = tostring(cell) | |||
if i == 1 then | |||
entries[ k ] = '<tr style="vertical-align:top">' .. entries[ k ] | |||
end | |||
if i == cols then | |||
entries[ k ] = entries[k] .. '</tr>' | |||
end | |||
end | end | ||
end | end | ||
root:wikitext(table.concat( entries, '\n' )) | |||
return tostring(root) | return tostring(root) | ||
end | end | ||
return p | return p |