Module:Aligned table: Difference between revisions

    (more mw.html)
    (more mw.html)
    Line 18: Line 18:
    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 28:
    :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 53:
    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
    i = math.fmod(k-1,cols) + 1
    cellcount = math.max(cellcount, k)
    local j = (k - i) / cols + 1
    end
    local cell = mw.html.create('td')
    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 = table: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 85:
    cell:cssText(colstyle[i])
    cell:cssText(colstyle[i])
    end
    end
    cell:wikitext(v)
    cell:wikitext(args[rows*(j - 1) + i] or '')
    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 the root table  
     
         return tostring(root)
         return tostring(root)
      end
      end


    return p
    return p