Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Canadian federal election results
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!
require('strict') local p = {} local templatestyles = 'Module:Canadian federal election results/styles.css' local tracking, preview local 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 == 'title' or k:find('^year[1-9]%d*$') or k:find('^seats[1-9]%d*[a-e]') then -- valid and not tracked else -- invalid local vlen = mw.ustring.len(k) k = mw.ustring.sub(k, 1, (vlen < 25) and vlen or 25) k = mw.ustring.gsub(k, '[^%w\-_ ]', '?') table.insert(tracking, '[[Category:Pages using canadian federal election results with unknown parameters|' .. k .. ']]') table.insert(preview, '"' .. k .. '"') end end local function makecell(frame, p, s) local res = '' for i = 1,#p do if p[i] ~= '' then local c = frame:expandTemplate{ title = 'Canadian party colour', args = {'CA', p[i]} } res = res .. frame:expandTemplate{ title = 'composition histogram', args = {c, s[i], title = p[i]} } end end return res end 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, {args['party' .. k .. 'a'] or '', args['party' .. k .. 'b'] or '', args['party' .. k .. 'c'] or '', args['party' .. k .. 'd'] or '', args['party' .. k .. 'e'] or ''}, {args['seats' .. k .. 'a'] or '0', args['seats' .. k .. 'b'] or '0', args['seats' .. k .. 'c'] or '0', args['seats' .. k .. 'd'] or '0', args['seats' .. k .. 'e'] or '0'})) end end local trackstr = (#tracking > 0) and table.concat(tracking, '') or '' if #preview > 0 then trackstr = require('Module:If preview')._warning({ 'Unknown parameters: ' .. table.concat(preview, '; ') }) end return frame:extensionTag{ name = 'templatestyles', args = { src = templatestyles} } .. tostring(root) .. trackstr end return p
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)
Templates used on this page:
Template:Lua
(
edit
)
Template:Module other
(
edit
)
Template:Module rating
(
edit
)
Template:Ombox
(
edit
)
Template:Sandbox other
(
edit
)
Template:Uses TemplateStyles
(
edit
)
Module:Arguments
(
edit
)
Module:Canadian federal election results/doc
(
edit
)
Module:Message box
(
edit
)
Module:Message box/configuration
(
edit
)
Module:Message box/ombox.css
(
edit
)
Module:String
(
edit
)
Module:Yesno
(
edit
)