Module:Medals table
Appearance
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
| This Lua module is used on approximately 16,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
Usage
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local navbar = require('Module:Navbar')._navbar
local p = {}
function p.createTable(frame, args)
if not args then
args = getArgs(frame)
end
local root = mw.html.create()
root = root
:tag('table')
:addClass('wikitable')
:addClass('sortable')
:addClass('plainrowheaders')
:addClass('jquery-tablesorter')
:css('text-align', 'center')
-- add the header row
root:tag('tr')
:tag('th')
:wikitext('Rank')
:tag('th')
:wikitext('Nation')
:tag('th')
:addClass('headerSort')
:css('width', '6em')
:css('background', 'gold')
:wikitext('Gold')
:tag('th')
:addClass('headerSort')
:css('background', 'silver')
:wikitext('Silver')
:tag('th')
:addClass('headerSort')
:css('background', '#c96')
:wikitext('Bronze')
:tag('th')
:wikitext('Total')
-- enumerate the rows
local rowNums = {}
for k,v in pairs(args) do
k = ''..k
local num = k:match('^nation(%d+)$')
if num then table.insert(rowNums, tonumber(num)) end
end
table.sort(rowNums)
-- for k,v in pairs(args) do
-- k = ''..k
-- local num = k:match('^nation(%d+)$')
-- if num then
-- root:tag('tr')
-- :tag('td')
-- :tag('td')
-- :wikitext(v)
-- end
-- end
-- For finding the matching args...
-- make num equal to the current number (i.e. 1 for nation 1)
-- then merge it and find the corresponding argument:
mw.logObject(rowNums)
for i, num in ipairs(rowNums) do
local nation = args['nation' .. num]
local gold = args['gold' .. num]
local silver = args['silver' .. num]
local bronze = args['bronze' .. num]
root:tag('tr')
:tag('td')
:wikitext('-')
:tag('td')
:wikitext(nation)
:tag('td')
:wikitext(gold)
:tag('td')
:wikitext(silver)
:tag('td')
:wikitext(bronze)
:tag('td')
:wikitext(tonumber(gold)+tonumber(silver)+tonumber(bronze))
end
return tostring(root)
end
return p