Module:Sandbox/Zackmann08/sometest

require('strict') local getArgs = require('Module:Arguments').getArgs local navbar = require('Module:Navbar')._navbar

local p = {} function p.hello(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