Module:Infobox election/sandbox: Difference between revisions

Content deleted Content added
add
update
Line 1:
local p = {}
local args = {}
local origArgs = {}
 
local InfoboxImage = require('Module:InfoboxImage').InfoboxImage
Line 59 ⟶ 57:
end
local image = {}
for i = 1, notblank(rargs['col3']) and 3 or 2, 1 do
image[i] = '| class="notheme" style="text-align:center;'
if not notblank(rargs['party' .. i]) and not notblank(rargs['color' .. i]) then
Line 204 ⟶ 202:
function p.infobox(frame)
-- Read args from input --
local origArgs = {}
local args = {}
for k,v in pairs(frame:getParent().args) do
if notblank(v) then origArgsargs[k] = mw.text.trim(v) end
end
for k,v in pairs(frame.args) do
if notblank(v) then origArgsargs[k] = mw.text.trim(v) end
end
 
-- Start defining infobox arguments --
local pagetitle = frame:getParent() and frame:getParent():getTitle() or frame:getTitle()
local etype = mw.ustring.lower(origArgsargs.type or '')
argslocal iargs = {
templatestyles = 'Infobox election/styles.css',
['child templatestyles'] = 'Screen reader-only/styles.css',
child = origArgsargs.child or origArgsargs.embed or '',
bodyclass = 'ib-election infobox-table' .. (notblank(origArgsargs.election_date) and 'vevent' or ''),
bodystyle = '',
titleclass = 'summary',
title = ((origArgsargs.child or origArgsargs.embed or '') == 'yes')
and (notblank(origArgsargs.election_name) and '<div style="background-color:#ddd; font-size:120%; font-weight:bold">'..origArgsargs.election_name..'</div>')
or (notblank(origArgsargs.election_name) and origArgsargs.election_name or pagetitle),
subheader1 = notblank(origArgsargs.flag_image)
and (InfoboxImage(
frame:newChild{ title = frame:getTitle(), args = {
image = origArgsargs.flag_image,
size = "50px",
alt = "",
Line 235:
} }
) .. "<hr />")
or (require('Module:CountryData').gettable(mw.getCurrentFrame(),origArgsargs.country).alias and (require('Module:flag').deco(
frame:newChild{ title = frame:getTitle(), args = {
[1] = origArgsargs.country,
variant = origArgsargs.flag_year,
size = "50px"
} }
Line 246:
subheader4 = 'TBD',
header1 = (etype == 'primary' or etype == 'presidential') and (
notblank(origArgsargs.votes_for_election) and (
'<hr />' .. origArgsargs.votes_for_election .. (
notblank(origArgsargs.needed_votes) and '<br />' .. origArgsargs.needed_votes .. ' votes needed to win'
)
) or ''
) or (
(etype == 'parliamentary' or etype == 'legislative' or etype == 'by-election') and (
notblank(origArgsargs.seats_for_election) and (
'<hr />' .. origArgsargs.seats_for_election .. (
notblank(origArgsargs.majority_seats) and '<br />' .. origArgsargs.majority_seats .. ' seats needed for a majority'
)
) or ''
Line 261:
),
data2 = notblank(origArgsargs.opinion_polls) and ('[[' .. origArgsargs.opinion_polls .. '|Opinion&nbsp;polls]]') or '',
label3 = 'Registered',
data3 = origArgsargs.registered,
label4 = 'Turnout',
data4 = origArgsargs.turnout,
label5 = 'Votes&nbsp;counted',
data5 = notblank(origArgsargs.votes_counted) and (
'<div class="center" style="width:auto;margin-left:auto;margin-right:auto;">' ..
_percentageBar(origArgsargs.votes_counted, origArgsargs.votes_counted .. '%', '1BCE0E') ..
"</div>as of '''" .. (origArgsargs.last_update or '') .. ' ' .. (origArgsargs.time_zone or '') .. "'''"
) or '',
label6 = 'Reporting',
data6 = notblank(origArgsargs.reporting) and (
'<div class="center" style="width:auto;margin-left:auto;margin-right:auto;">' ..
_percentageBar(origArgsargs.reporting, origArgsargs.reporting .. '%', '1BCE0E') ..
"</div>as of '''" .. (origArgsargs.last_update or '') .. ' ' .. (origArgsargs.time_zone or '') .. "'''"
) or '',
label7 = 'Declared',
data7 = notblank(origArgsargs.declared) and (
'<div class="center" style="width:auto;margin-left:auto;margin-right:auto;">' ..
_percentageBar(origArgsargs.declared, origArgsargs.declared .. '%', '1BCE0E') ..
"</div>as of '''" .. (origArgsargs.last_update or '') .. ' ' .. (origArgsargs.time_zone or '') .. "'''"
) or '',
}
-- bodystyle --
local width = 0
local map = false
for _, v in ipairs({'', '2', '3', '4'}) do
if notblank(origArgsargs['map' .. v]) or notblank(origArgsargs['map' .. v .. '_image']) then
map = true
local nWidth = mw.ustring.gsub(origArgsargs['map' .. v .. '_size'] or '300', '%s*px%s*$', '')
width = math.max(width, tonumber(nWidth) or 300)
end
end
if map then
argsiargs.bodystyle = tostring(math.min(300, width)) .. "px"
end
-- Start {{Infobox election/row}} lines --
 
local ordinals = {'First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth'}
local data10 = {'<nowiki />',
'{| style="background:transparent; color: inherit; width:100%;"',
}
for i = 1,3,1 do
-- Start defining row args that are the same for each row --
local origArgsrargs = {}
type = args.type,
divider = '<hr />',
ongoing = args.ongoing or 'no',
party_color = notblank(args.party_color) and args.party_color or 'yes',
image_size = args.image_size or '150x150px',
image_upright = args.image_upright,
party_label = args.party_label or 'Party',
vote_type = args.vote_type or 'Popular',
opinion_polls = args.opinion_polls,
col3 = ''
}
for j = 1,6,1 do
rargs[tostring(j) .. 'blank'] = args[tostring(j) .. 'blank']
end
-- Start defining row args that are different for each row --
local startnum = (3 * (i - 1))
local headernum = startnum
if (i > 1) and (notblank(args.party3)) then
headernum = headernum - 1
end
if (i == 3) and (notblank(args.party6)) then
headernum = headernum - 1
end
-- Define row args that come in sets of 3 --
for j = 1,3,1 do
rargs['header' .. tostring(j)] = ordinals[headernum + j] .. ' party'
for _, v in ipairs({
'image?', 'image?_size', 'image?_upright', 'pageimage?', 'nominee?',
'candidate?', 'leader?', 'party?', 'alliance?', 'home_state?',
'running_mate?', 'college_voted', 'electoral_vote?', 'delegate_count?', 'states_carried?',
'leader_since?', 'leaders_seat?', 'last_election?',
'seats_before?', 'seats_needed?', 'seats?', 'seats_after?', 'seat_change?',
'popular_vote?', 'percentage?', 'swing?',
'1data?', '2data?', '3data?', '4data?', '5data?', '6data?'
}) do
rargs[mw.ustring.gsub(v, '?', tostring(j))] = args[mw.ustring.gsub(v, '?', tostring(j + startnum))]
end
rargs['color' .. tostring(j)] = notblank(args['color' .. tostring(startnum + j)]) and args['color' .. tostring(startnum + j)] or args['colour' .. tostring(startnum + j)]
rargs['party' .. tostring(j) .. '_name'] = notblank(args['party' .. tostring(startnum + j) .. '_name']) and args['party' .. tostring(startnum + j) .. '_name'] or args['party_name']
rargs['alliance' .. tostring(j) .. '_name'] = notblank(args['alliance' .. tostring(startnum + j) .. '_name']) and args['alliance' .. tostring(startnum + j) .. '_name'] or args['alliance_name']
end
-- Determine if there is a third column --
for _, v in ipairs({
'color', 'colour', 'image', 'nominee', 'candidate',
'leader', 'party', 'alliance', 'home_state', 'running_mate',
'electoral_vote', 'delegate_count', 'states_carried',
'leader_since', 'leaders_seat', 'last_election',
'seats_before', 'seats_needed', 'seats', 'seats_after', 'seat_change',
'popular_vote', 'percentage', 'swing',
'1data', '2data', '3data', '4data', '5data', '6data'
}) do
if notblank(args[v .. tostring(3 * i)]) then
rargs.col3 = 'yes'
break
end
end
-- Insert data --
table.insert(data10, '|-')
table.insert(data10, _row(frame, rargs))
end
iargs.data10 = table.concat(data10, '\n') .. '|}'
-- Maps --
-- Return infobox --
return require('Module:Infobox').infoboxTemplate(
frame:newChild{ title = frame:getTitle(), args = argsiargs }
)
end