Module:Infobox election/sandbox
Appearance
![]() | This is the module sandbox page for Module:Infobox election (diff). |
![]() | This module depends on the following other modules: |
Implements {{Infobox election/row}} and {{Infobox election/shortname}} with a reduced post-expand include size
Usage
{{#invoke:Infobox election|row}}
{{#invoke:Infobox election|shortname}}
local p = {}
local args = {}
local origArgs = {}
local InfoboxImage = require('Module:InfoboxImage').InfoboxImage
local function notblank(v)
return (mw.text.trim(v or "") ~= "")
end
local function _row(frame, rargs)
local delink = require('Module:Delink')._delink
local fetch = require('Module:Political party')._fetch
local output = {'|-'}
setmetatable(a, { __call = function (t, v) t[#t+1] = v end }) -- Append to array by calling it
if notblank(rargs.divider) and (
notblank(rargs.party1) or notblank(rargs.color1) or notblank(rargs.leader1) or notblank(rargs.party2) or notblank(rargs.color2) or notblank(rargs.leader2) or notblank(rargs.party3) or notblank(rargs.color3) or notblank(rargs.leader3)
) then
output('| colspan=4 | ' .. rargs.divider)
end
output('|- class="sr-only"')
if rargs.ongoing ~= "yes" and (
mw.ustring.lower(rargs.type) == "parliamentary" or mw.ustring.lower(rargs.type) == "legislative"
) and (
notblank(rargs.party1) or notblank(rargs.party2) or notblank(rargs.party2)
) then
output('! style="text-align:left;" | ')
output('! style="text-align:center" | ' .. (notblank(rargs.party1) and rargs.header1 or ''))
output('! style="text-align:center" | ' .. (notblank(rargs.party2) and rargs.header2 or ''))
if notblank(rargs.col3) then
output('! style="text-align:center" | ' .. (notblank(rargs.party3) and rargs.header3 or ''))
end
end
output('|-')
-- Images --
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
output('! <br />' .. rargs.filler)
else
output('| ')
end
local image = {}
for i = 1, 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
image[i] = image[i] .. 'width:0;'
end
if notblank(rargs['color' .. i]) then
image[i] = image[i] .. 'border-bottom: 6px solid #' .. mw.ustring.gsub(mw.ustring.gsub(rargs['color' .. i],'#',''),'#','')
elseif rargs.party_color ~= 'no' and notblank(rargs['party'] .. i) then
local color = mw.ustring.replace(rargs['party' .. i], '^(%[%[%s*[^%]%[]*%]%]).*$', '%1')
color = delink({[1] = color, wikilinks = 'target'})
color = fetch({[1] = color, [2] = 'color', error = 'NOTHERE'})
if color ~= 'NOTHERE' then
image[i] = image[i] .. 'border-bottom: 6px solid' .. color
end
end
image[i] = image[i] .. ';" | ' .. InfoboxImage( frame:newChild{
title = frame:getTitle(), args = {
image = rargs['image' .. i] or '',
size = notblank(rargs['image' .. i .. '_size']) and rargs['image' .. i .. '_size'] or (rargs.image_size or ''),
alt = rags['alt' .. i] or '',
upright = notblank(rargs['image' .. i .. '_upright']) and rargs['image' .. i .. '_upright'] or (
(notblank(rargs['col3']) and notblank(rargs['image3'])) and '0.4' or '0.6'
),
suppressplaceholder = 'yes',
class = notblank(rargs['pageimage' .. i] and '' or 'notpageimage noresize'),
}
} )
output(image[i])
end
end
output('|-')
-- Presidential & by-election nominee --
end
function p.infobox(frame)
for k,v in frame:getParent().args do
if notblank(v) then origArgs[k] = mw.text.trim(v) end
end
for k,v in frame.args do
if notblank(v) then origArgs[k] = mw.text.trim(v) end
end
local width = math.max(
(origArgs.map_image or origArgs.map) and (mw.ustring.match((origArgs.map_size or 300),"(%d*)")) or 0,
(origArgs.map2_image or origArgs.map2) and (mw.ustring.match((origArgs.map2_size or 300),"(%d*)")) or 0,
(origArgs.map3_image or origArgs.map3) and (mw.ustring.match((origArgs.map3_size or 300),"(%d*)")) or 0,
(origArgs.map4_image or origArgs.map4) and (mw.ustring.match((origArgs.map4_size or 300),"(%d*)")) or 0
)
local pagetitle = frame:getParent() and frame:getParent():getTitle() or frame:getTitle()
args = {
child = origArgs.child or origArgs.embed,
bodyclass = origArgs.election_date and origArgs.vevent or nil,
bodystyle = "line-height:1.5em;" .. ((width > 0) and ("width:"..width.."px;") or ""),
titleclass = "summary",
titlestyle = "font-size:125%;",
title = ((origArgs.child or origArgs.embed) == yes)
and (origArgs.election_name and '<div style="background-color:#ddd; font-size:120%; font-weight:bold">'..origArgs.election_name..'</div>')
or (origArgs.election_name or (frame:getParent() and frame:getParent():getTitle() or frame:getTitle())),
datastyle = "text-align:center;",
labelstyle = "width:5em;white-space:nowrap;",
subheaderstyle = "line-height:130%;",
subheader1 = origArgs.flag_image
and (InfoboxImage(
frame:newChild{ title = frame:getTitle(), args = {
image = origArgs.flag_image,
size = "50px",
alt = "",
link = ""
} }
) .. "<hr />")
or (require('Module:CountryData').gettable(mw.getCurrentFrame(),origArgs.country).alias and (require('Module:flag').deco(
frame:newChild{ title = frame:getTitle(), args = {
[1] = origArgs.country,
variant = origArgs.flag_year,
size = "50px"
} }
) .. "<hr />") ),
}
return require('Module:Infobox').infoboxTemplate(
frame:newChild{ title = frame:getTitle(), args = args }
)
end