Module:NPVIC table

local p = {}

local state_links = { ["AL"] = "Alabama", ["AK"] = "Alaska", ["AZ"] = "Arizona", ["AR"] = "Arkansas", ["CA"] = "California", ["CO"] = "Colorado", ["CT"] = "Connecticut", ["DE"] = "Delaware", ["DC"] = "District of Columbia", ["FL"] = "Florida", ["GA"] = "Georgia", ["HI"] = "Hawaii", ["ID"] = "Idaho", ["IL"] = "Illinois", ["IN"] = "Indiana", ["IA"] = "Iowa", ["KS"] = "Kansas", ["KY"] = "Kentucky", ["LA"] = "Louisiana", ["ME"] = "Maine", ["MD"] = "Maryland", ["MA"] = "Massachusetts", ["MI"] = "Michigan", ["MN"] = "Minnesota", ["MS"] = "Mississippi", ["MO"] = "Missouri", ["MT"] = "Montana", ["NE"] = "Nebraska", ["NV"] = "Nevada", ["NH"] = "New Hampshire", ["NJ"] = "New Jersey", ["NM"] = "New Mexico", ["NY"] = "New York", ["NC"] = "North Carolina", ["ND"] = "North Dakota", ["OH"] = "Ohio", ["OK"] = "Oklahoma", ["OR"] = "Oregon", ["PA"] = "Pennsylvania", ["RI"] = "Rhode Island", ["SC"] = "South Carolina", ["SD"] = "South Dakota", ["TN"] = "Tennessee", ["TX"] = "Texas", ["UT"] = "Utah", ["VT"] = "Vermont", ["VA"] = "Virginia", ["WA"] = "Washington", ["WV"] = "West Virginia", ["WI"] = "Wisconsin", ["WY"] = "Wyoming" }

function p._showtable(frame, args) local reference_heading = frame:expandTemplate{title = 'Reference column heading'} local root = mw.html.create('table') :addClass('wikitable sortable') :css('line-height', 1.2) :css('margin-left', 'auto') :css('margin-right', 'auto') -- table title root:tag('caption'):wikitext('Jurisdictions enacting law to join the National Popular Vote Interstate Compact') -- header row local row = root:tag('tr') row:tag('th'):attr('scope', 'col'):wikitext('No.') row:tag('th'):attr('scope', 'col'):wikitext('Jurisdiction') row:tag('th'):attr('scope', 'col'):attr('data-sort-type', 'date'):wikitext('Date adopted') row:tag('th'):attr('scope', 'col'):attr('class','unsortable'):wikitext('Method of adoption') row:tag('th'):attr('scope', 'col'):attr('class','unsortable'):wikitext(reference_heading) row:tag('th'):attr('scope', 'col'):wikitext('Current electoral votes (EVs)') local k = 1 local EVs = 0 while args['state' .. k] do local seats = args['state' .. k] == 'DC' and 1 or frame:expandTemplate{ title = 'USHRseats', args = {args['state' .. k]}} row = root:tag('tr') row:tag('th'):attr('scope', 'row'):wikitext(k) row:tag('td'):wikitext(state_links[args['state' .. k]] or args['state' .. k]) row:tag('td'):css('text-align','right'):wikitext(args['date' .. k]) row:tag('td'):wikitext(args['method' .. k]) row:tag('td'):css('text-align','center'):wikitext(args['ref' .. k]) row:tag('td'):css('text-align','center'):wikitext(tonumber(seats) + 2) EVs = EVs + tonumber(seats) + 2 k = k + 1 end local percent = frame:expandTemplate{ title = 'percent', args = { EVs, 270, 1} } row = root:tag('tr'):addClass('sortbottom') row:tag('th'):attr('colspan', 5):css('text-align', 'right'):wikitext('Total') row:tag('th'):css('text-align', 'center'):wikitext(EVs) row = root:tag('tr'):addClass('sortbottom') row:tag('th'):attr('colspan', 5):css('text-align', 'right'):wikitext('Percentage of the 270 EVs needed') row:tag('th'):css('text-align', 'center'):wikitext(percent)

return root end

function p.main(frame) local args = require('Module:Arguments').getArgs(frame) return p._showtable(frame, args) end

return p