Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Gonnym/sometest10
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
--[[ 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 --]]
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Gonnym/sometest10/doc
(
edit
)