require('strict')local p = local templatestyles = 'Module:Canadian federal election results/styles.css'local tracking, previewlocal rows = local rowcount = 0
local function checkarg(k,v) if not k or type(k) ~= 'string' then return end if k:find('^party[1-9]%d*[a-e]$') then -- valid and not tracked if k:find('^party[1-9]%d*a$') then local n = mw.ustring.gsub(k, '^party([1-9]%d*)[a-e]', '%1') table.insert(rows, tonumber(n)) rowcount = rowcount + 1 end elseif k
local function makecell(frame, p, s) local res = for i = 1,#p do if p[i] ~= then local c = frame:expandTemplate res = res .. frame:expandTemplate end end return resend
function p.main(frame) local args = require('Module:Arguments').getArgs(frame) tracking, preview =, for k, v in pairs(args) do if v ~= then checkarg(k,v) end end table.sort(rows) local root = mw.html.create('table') :addClass('ca-fed-elect-results wikitable floatright') root:tag('caption'):wikitext(args['title'] or 'Electoral history') local row = root:tag('tr') row:tag('th'):attr('scope','col'):wikitext('Year') row:tag('th'):attr('scope','col'):wikitext('Results') for j = 1, rowcount do local k = rows[j] if args['party' .. k .. 'a'] then row = root:tag('tr') row:tag('th'):attr('scope', 'row'):wikitext(args['year' .. k] or '?') row:tag('td'):wikitext(makecell(frame, , )) end end local trackstr = (#tracking > 0) and table.concat(tracking, ) or if #preview > 0 then trackstr = require('Module:If preview')._warning end
return frame:extensionTag .. tostring(root) .. trackstr
end
return p