Content deleted Content added
Start working on _row |
Finish /row |
||
Line 4:
local InfoboxImage = require('Module:InfoboxImage').InfoboxImage
local delink = require('Module:Delink')._delink
local fetch = require('Module:Political party')._fetch
local notblank = function (v) return (mw.text.trim(v or "") ~= "") end
local ucfirst = function (s) return mw.ustring.upper(mw.ustring.sub(s,1,1)) .. mw.ustring.gsub(mw.ustring.sub(s,2), '_', ' ') end
local function _row(frame, rargs)
local output = {'|-'}
setmetatable(a, { __call = function (t, v) t[#t+1] = v end }) -- Append to array by calling it
function threeCells(cellType, title, always, shortname)
local centeredCell = function (key)
local name = shortname and p._shortname(rargs[key .. '_name'], rargs[key]) or (rargs[key] or '')
return ('| style="' .. (notblank(rargs[key]) and 'width:75px;' or '') .. 'text-align:center" | ' .. name )
end
if always or ( notblank(rargs[cellType .. '1']) or notblank(rargs[cellType .. '2']) or notblank(rargs[cellType .. '3']) ) then
output('|-')
output('! style="width:75px;text-align:left" |' .. (title or ucfirst(cellType or '')))
output(centeredCell(cellType .. '1'))
output(centeredCell(cellType .. '2'))
if always or notblank(rargs.col3) then
output(centeredCell(cellType .. '3'))
end
end
end
if notblank(rargs.divider) and (
Line 34 ⟶ 49:
end
end
-- Images --
output('|-')
if notblank(rargs.party1) or notblank(rargs.color1) or notblank(rargs.image1) or notblank(rargs.party2) or notblank(rargs.color2) or notblank(rargs.image2) or notblank(rargs.party3) or notblank(rargs.color3) or notblank(rargs.image3) then
if notblank(rargs.filler) then
Line 73 ⟶ 88:
end
end
-- Presidential & by-election nominee --
if notblank(rargs['nominee1']) or notblank(rargs['nominee2']) or notblank(rargs['nominee3']) then
if ({primary = 1, presidential = 1, ['by-election'] = 1})[mw.ustring.lower(rargs.type)] == 1 then
threeCells('nominee', '', true) -- nominee, no alternative title, always show
end
else
threeCells('candidate') -- nominee
end
-- Party leader --
if mw.ustring.lower(rargs.type) == 'parliamentary' or mw.ustring.lower(rargs.type) == 'legislative' then
threeCells('leader')
end
-- Party name --
threeCells('party', (notblank(rargs.party_label) and rargs.party_label or 'Party'), false, true) -- party, alternative name, don't always show, use shortname
-- Alliance name --
threeCells('alliance', '', false, true) -- alliance, not alternative title, don't always show, use shortname
-- Primary or presidential
if mw.ustring.lower(rargs.type) == 'primary' or mw.ustring.lower(rargs.type) == 'presidential' then
-- Home state --
threeCells('home_state')
-- Running mate --
if mw.ustring.lower(rargs.type) == 'presidential' then
threeCells('running_mate')
-- Electoral vote --
threeCells('electoral_vote', (rargs.college_votes == 'no' and 'Projected e' or 'E') .. 'lectoral vote')
end
-- Delegate count --
threeCells('delegate_count', (rargs.ongoings == 'yes' and 'Estimated d' or 'D') .. 'elegate count')
-- States carried --
threeCells('states_carried', mw.ustring.lower(rargs.type) == 'primary' and 'Contests won' or 'States carried')
end
-- Parliamentary or legistlative --
if mw.ustring.lower(rargs.type) == 'parliamentary' or mw.ustring.lower(rargs.type) == 'legislative' then
-- Leader since --
threeCells('leader_since')
-- Leader's seat --
threeCells('leaders_seat', "Leader's seat")
-- Last election --
threeCells('last_election')
-- Seats before --
threeCells('seats_before', rargs.ongoing == 'yes' and 'Current seats' or 'Seats before')
-- Ongoing --
if rargs.ongoing == 'yes' then
-- Seats needed --
threeCells('seats_needed')
-- Not ongoing --
else
-- Seats won --
threeCells('seats', 'Seats won')
-- Seats after --
threeCells('seats_after')
-- Seat change --
threeCells('seat_change')
end
end
-- Primary or not ongoing --
if rargs.ongoing ~= 'yes' or rargs.type == 'primary' then
-- Popular vote --
threeCells('popular_vote', (rargs.vote_type or 'Popular') .. ' vote')
-- Percentage --
threeCells('percentage')
-- Primary or presidential
if mw.ustring.lower(rargs.type) == 'primary' or mw.ustring.lower(rargs.type) == 'presidential' then
-- Counties won --
threeCells('counties_won')
-- Counties 25% threshold --
threeCells('counties_threshhold', 'Counties with 25% vote')
end
end
-- Swing --
if (mw.ustring.lower(rargs.type) == 'parliamentary' or mw.ustring.lower(rargs.type) == 'legislative') and
rargs.ongoing ~= 'yes' and notblank(rargs.swing1) then
threeCells('swing')
end
-- Blank fields --
for i = 1,6,1 do
if notblank(rargs[i .. 'blank']) then
threeCells(i ..'data', rargs[i .. 'blank'])
end
end
end
function p._shortname(link, name)
if link ~= 'no' and notblank(name) and delink({[1] = name, wikilinks = 'target'}) == name then
-- the below array items are intentionally missing the training 's'
local names = {
independent = '[[Independent politician|' .. name .. ']]',
miscellaneous = '[[Independent politician|DIV]]',
other = 'Others',
['other parties and independent'] = 'Others & [[Independent politician|IND]]',
regionalist = '[[Regionalism (politics)|Regionalists]]',
tbc = '[[To be announced|TBC]]',
tbd = '[[To be announced|TBD]]',
vacant = '[[Casual vacancy|Vacant]]'
}
return names[mw.ustring.gsub(mw.ustring.lower(name), 's$', '')] or
('[[' .. name .. '|' .. fetch({[1] = name, [2] = 'shortname'}) .. ']]')
end
return name or ''
end
|