Documentation for this module may be created at Module:Sandbox/Gonnym/sometest10/doc
--[[
Option 1: Pass cell data and join the cells in main module.
Option 2: Pass a complete args table and get a finished table.
--]]
--[[
List of public functions:
-- createTable(args)
-- createTableRow(args)
-- createAndAddTableRow(tableObject, args)
-- createColumnHeaderCell(args)
-- createAndAddColumnHeaderCell(rowObject, args)
-- createRowCell(args)
-- createAndAddRowCell(rowObject, args)
--]]
local p = {}
--[[
Local function which is used to add relevent tags (attributes, css and others) to the current table object.
Parameters:
-- class — If used, will add a class using the value entered.
-- rowspan — If used, will add the rowspan attribute and set its number as the value entered.
-- colspan — If used, will add the colspan attribute and set its number as the value entered.
-- id — If used, will add an ID attribute, using the value entered.
-- background — If used, will add the background css, and set it to the value entered.
-- backgroundColor — If used, will add the backgroundColor css, and set it to the value entered.
-- borderBottom — If used, will add the borderBottom css, and set it to the value entered.
-- lineHeight — If used, will add the lineHeight css, and set it to the value entered.
-- padding — If used, will add the padding css, and set it to the value entered.
-- textAlign — If used, will add the textAlign css, and set it to the value entered.
-- width — If used, will add the width css, and set it to the value entered.
-- newline — If used, will add a newline.
-- text — If used, will add text using the value entered.
-]]
local function setTags(object, args)
--------------- Class section ---------------
-- Set class.
if (args.class) then
object:addClass(args.class)
end
--[[
Is more than 1 class possible (not including those already handled by the createTable() by default)?
-- Set another class.
if (args.class2) then
object:addClass(args.class2)
end
--]]
--------------- Attribute section ---------------
-- Set rowspan.
if (args.rowspan) then
object:attr('rowspan', args.rowspan)
end
-- Set colspan.
if (args.colspan) then
object:attr('colspan', args.colspan)
end
-- Set ID.
if (args.id) then
object:attr('id', args.id)
end
--------------- CSS section ---------------
-- Set background.
if (args.background) then
object:css('background', args.background)
end
-- Set background-color.
if (args.backgroundColor) then
object:css('background-color', args.backgroundColor)
end
-- Set border-bottom.
if (args.borderBottom) then
object:css('border-bottom', args.borderBottom)
end
-- Set color.
if (args.color) then
object:css('color', args.color)
end
-- Set display.
if (args.display) then
object:css('display', args.borderBottom)
end
-- Set line-height.
if (args.lineHeight) then
object:css('line-height', args.lineHeight)
end
-- Set padding.
if (args.padding) then
object:css('padding', args.padding)
end
-- Set text-align.
if (args.textAlign) then
object:css('text-align', args.textAlign)
end
-- Set width.
if (args.width) then
object:css('width', args.width)
end
--------------- Others ---------------
-- Set newline.
if (args.newline) then
object:newline()
end
-- Set text.
if (args.text) then
object:wikitext(args.text)
end
return object
end
------------Option 1---------------
--[[
Public function which creates a wikitable.
Parameters:
-- plainrowheaders — true or false; If true sets the table as "plainrowheaders".
-- sortable — true or false; If true sets the table as "sortable".
-- textAlign — Sets the value as the table's text-align.
-- width — Sets the value as the table's width.
-- caption — Sets the value as the table's caption.
-]]
function p.createTable(args)
-- Create the root mw.html object to return.
local root = mw.html.create('table')
-- Create wikitable.
root:addClass('wikitable')
-- Set plainrowheaders.
if (args.plainrowheaders) then
root:addClass('plainrowheaders')
end
-- Set sortable.
if (args.sortable) then
root:addClass('sortable')
end
root = setTags(root, args)
-- Set caption.
if (args.caption) then
root:tag('caption'):wikitext(args.caption)
end
return root
end
--[[
Public function which creates a table row.
Parameters: See setTags() for complete parameter list.
-]]
function p.createTableRow(args)
-- Create the table row mw.html object to return.
local row = mw.html.create('tr')
return setTags(row, args)
end
--[[
Public function which creates a table row, and adds it to the table.
Parameters:
-- tableObject — The parent table of the row.
-- See setTags() for complete parameter list.
-]]
function p.createAndAddTableRow(tableObject, args)
if (args) then
mw.log(true)
else
mw.log(false)
end
local row = p.createTableRow(args)
return tableObject:node(row)
end
--[[
Public function which creates a column header cell.
Parameters: See setTags() for complete parameter list.
-]]
function p.createColumnHeaderCell(args)
-- Create the table header mw.html object to return.
local cell = mw.html.create('th'):attr('scope', 'col')
return setTags(cell, args)
end
--[[
Public function which creates a column header cell, and adds the cell to the row object.
Parameters:
-- rowObject — The parent row of the current cell.
-- See setTags() for complete parameter list.
-]]
function p.createAndAddColumnHeaderCell(rowObject, args)
local cell = p.createColumnHeaderCell(args)
return rowObject:node(cell)
end
--[[
Public function which creates a row header cell.
Parameters:
-- headerCell — true or false; If true will set the cell to "th", if false, will set it to "td".
-- See setTags() for complete parameter list.
-]]
function p.createRowCell(args)
local cell
-- Check if the cell is a header or data cell.
if (args.headerCell) then
-- Create the table header mw.html object to return.
cell = mw.html.create('th'):attr('scope', 'row')
else
-- Create the table data mw.html object to return.
cell = mw.html.create('td')
end
return setTags(cell, args)
end
--[[
Public function which creates a row header cell, and adds it to the table.
Parameters:
-- rowObject — The parent row of the current cell.
-- See createRowCell() and setTags() for complete parameter list.
-]]
function p.createAndAddRowCell(rowObject, args)
local cell = p.createRowCell(args)
return rowObject:node(cell)
end
return p
--[[
------------Option 2---------------
local root
local function createTable2(args)
-- Create the root mw.html object to return
root = mw.html.create()
-- Create wikitable.
root:addClass('wikitable')
-- Set plainrowheaders.
if (args.plainrowheaders) then
root:addClass('plainrowheaders')
end
-- Set sortable.
if (args.sortable) then
root:addClass('sortable');
end
-- Set text-align.
if (args.text-align) then
root:css('text-align', args.textAlign)
end
-- Set width.
if (args.width) then
root:css('width', args.width)
end
-- Set caption.
if (args.caption) then
root:tag('caption'):wikitext(args.caption)
end
return root
end
local function createTableRow2(args)
local row = root:tag('tr')
-- TODO: add logic.
setTags(row, args)
-- TODO: create loop here
if (columnCell) then
createColumnHeaderCell(args)
else
createRowCell(args)
end
end
local function createColumnHeaderCell2(args)
headerRow:tag('th'):attr('scope', 'col')
-- TODO: add logic.
setTags(headerRow, args)
end
local function createRowCell2(args)
-- Check if the cell is a header or data cell.
if (args.headerCell) then
row:tag('th')
else
row:tag('td')
end
row:attr('scope', 'row')
-- TODO: add logic.
row = setTags(row, args)
return row
end
--]]