Module:InfoboxElection

From RetroMC
Jump to navigation Jump to search

Documentation for this module may be created at Module:InfoboxElection/doc

-- Module:InfoboxElection

local p = {}

function p.infobox(frame)
    local getArgs = require('Module:Arguments').getArgs
    local args = getArgs(frame)

    local electionName = args.name or ""
    local electionDate = args.date or ""
    local electionLocation = args.location or ""
    local electionParticipants = args.participants or ""
    local electionWinner = args.winner or ""

    local output = mw.html.create("table")
    output:addClass("infobox")
    output:addClass("wikitable")
    output:addClass("plainlist")

    -- Election Name
    if electionName ~= "" then
        local row = output:tag("tr")
        row:tag("th"):wikitext("Election Name")
        row:tag("td"):wikitext(electionName)
    end

    -- Election Date
    if electionDate ~= "" then
        local row = output:tag("tr")
        row:tag("th"):wikitext("Date")
        row:tag("td"):wikitext(electionDate)
    end

    -- Election Location
    if electionLocation ~= "" then
        local row = output:tag("tr")
        row:tag("th"):wikitext("Location")
        row:tag("td"):wikitext(electionLocation)
    end

    -- Election Participants
    if electionParticipants ~= "" then
        local row = output:tag("tr")
        row:tag("th"):wikitext("Participants")
        row:tag("td"):wikitext(electionParticipants)
    end

    -- Election Winner
    if electionWinner ~= "" then
        local row = output:tag("tr")
        row:tag("th"):wikitext("Winner")
        row:tag("td"):wikitext(electionWinner)
    end

    return tostring(output)
end

return p