Module:Infobox AFL biography/convert
Appearance
-- [SublimeLinter luacheck-globals:mw]
-- This module serves to convert <br>-delimited teams/years parameters in
-- [[Template:Infobox AFL biography]] to their equivalent numbered pairs. Simply
-- replace "{{Infobox AFL biography" with
-- "{{subst:#invoke:Infobox AFL biography/convert|main" and press "Save".
local p = {}
local getBuffer, print = require("Module:OutputBuffer")()
local function printfd(formatString, ...)
local default = ""
local args, argsNum = {...}, select("#", ...)
local newArgs = {}
for i = 1, argsNum do
if args[i] ~= nil then
table.insert(newArgs, args[i])
else
table.insert(newArgs, default)
end
end
print(string.format(formatString, unpack(newArgs)))
end
local function processTeamsYears(teams, years, gamesGoals, teamsParam, yearsParam, gamesGoalsParam, oldGamesGoalsParam)
local function extractItems(s, t)
local sentinel = "😂" -- WTF, Lua?
string.gsub(string.gsub(s, "<[Bb][Rr] */?>", " " .. sentinel .. " "),
"[^" .. sentinel .. "]+",
function(c) table.insert(t, string.match(c, "^%s*(.-)%s*$")) end)
end
local newTeams = {}
extractItems(teams, newTeams)
local newYears = {}
extractItems(years, newYears)
local newGamesGoals = {}
extractItems(gamesGoals, newGamesGoals)
if #newTeams ~= #newYears or #newYears ~= #newGamesGoals or #newGamesGoals ~= #newTeams then
printfd("<!-- Template:Infobox AFL biography conversion error: " ..
"Parameters not of equal length. -->")
printfd("| %ss = %s", teamsParam, teams)
printfd("| %s = %s", yearsParam, years)
printfd("| %s = %s", oldGamesGoalsParam, gamesGoals)
return
end
c = 1
for i = 1, #newTeams do
if newYears[i] ~= "" or newTeams[i] ~= "" then
printfd("| %s%s = %s", yearsParam, c,
newYears[i] ~= "" and newYears[i] or
"<!-- Template:Infobox AFL biography conversion error: " ..
"years missing. -->")
printfd("| %s%s = %s", teamsParam, c,
newTeams[i] ~= "" and newTeams[i] or
"<!-- Template:Infobox AFL biography conversion error: " ..
"team missing. -->")
printfd("| %s%s = %s", gamesGoalsParam, c,
newGamesGoals[i] ~= "" and newGamesGoals[i] or
"<!-- Template:Infobox AFL biography conversion error: " ..
"games(goals) missing. -->")
c = c + 1
end
end
end
function p._main(args)
print("{{Infobox AFL biography")
if args.embed then
printfd("| embed = %s", args.embed)
end
if args.headercolor then
printfd("| header-color = %s", args.headercolor)
end
printfd("| name = %s", args.name or args.playername)
printfd("| image = %s", args.image)
if args.image_size or args.imagesize then
printfd("| image_size = %s", args.image_size or args.imagesize)
end
if args.image or args.alt then
printfd("| alt = %s", args.alt)
end
if args.image or args.caption then
printfd("| caption = %s", args.caption)
end
if args.fullname then
printfd("| fullname = %s", args.fullname)
end
if args.nickname then
printfd("| nickname = %s", args.nickname)
end
printfd("| birth_date = %s", args.birth_date)
printfd("| birth_place = %s", args.birth_place)
printfd("| death_date = %s", args.death_date)
printfd("| death_place = %s", args.death_place)
if args.originalteam then
printfd("| originalteam = %s", args.originalteam)
end
if args.draftpick then
printfd("| draftpick = %s", args.draftpick)
end
if args.debutdate then
printfd("| debutdate = %s", args.debutdate)
end
if args.debutteam then
printfd("| debutteam = %s", args.debutteam)
end
if args.debutopponent then
printfd("| debutopponent = %s", args.debutopponent)
end
if args.debutstadium then
printfd("| debutstadium = %s", args.debutstadium)
end
printfd("| heightweight = %s", args.heightweight)
printfd("| position = %s", args.position)
if args.otheroccupation then
printfd("| otheroccupation = %s", args.otheroccupation)
end
if args.currentclub then
printfd("| currentclub = %s", args.currentclub)
end
if args.guernsey then
printfd("| guernsey = %s", args.guernsey)
end
if args.statsend then
printfd("| statsend = %s", args.statsend)
end
if args.coachstatsend then
printfd("| coachstatsend = %s", args.coachstatsend)
end
if args.repstatsend then
printfd("| repstatsend = %s", args.repstatsend)
end
if args.playingteams then
printfd("| playingteams = %s", args.playingteams)
end
if args.coachingteams then
printfd("| coachingteams = %s", args.coachingteams)
end
if args.clubs and args.years and args.gamesgoals then
processTeamsYears(args.clubs, args.years, args.gamesgoals,
"club", "years", "games_goals", "games(goals)")
elseif args.clubs or args.years or args.gamesgoals then
print("<!-- Template:Infobox AFL biography conversion error: " ..
"Template is missing expected parameters. -->")
printfd("| clubs = %s", args.clubs)
printfd("| years = %s", args.years)
printfd("| games(goals) = %s", args.gamesgoals)
end
if args.gamesgoalstotal then
printfd("| games_goalstotal = %s", args.gamesgoalstotal)
end
if args.sooteams and args.sooyears and args.soogamesgoals then
processTeamsYears(args.sooteams, args.sooyears, args.soogamesgoals,
"sooteam", "sooyears", "soogames_goals", "soogames(goals)")
elseif args.sooteams or args.sooyears or args.soogamesgoals then
print("<!-- Template:Infobox AFL biography conversion error: " ..
"Template is missing expected parameters. -->")
printfd("| sooteams = %s", args.sooteams)
printfd("| sooyears = %s", args.sooyears)
printfd("| soogames(goals) = %s", args.soogamesgoals)
end
if args.soogamesgoalstotal then
printfd("| soogames_goalstotal = %s", args.soogamesgoalstotal)
end
if args.nationalteams and args.nationalyears and args.nationalgamesgoals then
processTeamsYears(args.nationalteams, args.nationalyears, args.nationalgamesgoals,
"nationalteam", "nationalyears", "nationalgames_goals", "nationalgames(goals)")
elseif args.nationalteams or args.nationalyears or args.nationalgamesgoals then
print("<!-- Template:Infobox AFL biography conversion error: " ..
"Template is missing expected parameters. -->")
printfd("| nationalteams = %s", args.nationalteams)
printfd("| nationalyears = %s", args.nationalyears)
printfd("| nationalgames(goals) = %s", args.nationalgamesgoals)
end
if args.nationalgamesgoalstotal then
printfd("| nationalgames_goalstotal = %s", args.nationalgamesgoalstotal)
end
if args.coachclubs and args.coachyears and args.coachgameswins then
processTeamsYears(args.coachclubs, args.coachyears, args.coachgameswins,
"coachclub", "coachyears", "coachgames_wins", "coachgames(wins)")
elseif args.coachclubs or args.coachyears or args.coachgameswins then
print("<!-- Template:Infobox AFL biography conversion error: " ..
"Template is missing expected parameters. -->")
printfd("| coachclubs = %s", args.coachclubs)
printfd("| coachyears = %s", args.coachyears)
printfd("| coachgames(wins) = %s", args.coachgameswins)
end
if args.coachgameswinstotal then
printfd("| coachgames_winstotal = %s", args.coachgameswinstotal)
end
if args.umpireyears1 then
printfd("| umpireyears1 = %s", args.umpireyears1)
end
if args.umpireleague1 then
printfd("| umpireleague1 = %s", args.umpireleague1)
end
if args.umpirerole1 then
printfd("| umpirerole1 = %s", args.umpirerole1)
end
if args.umpiregames1 then
printfd("| umpiregames1 = %s", args.umpiregames1)
end
if args.umpireyears2 then
printfd("| umpireyears2 = %s", args.umpireyears2)
end
if args.umpireleague2 then
printfd("| umpireleague2 = %s", args.umpireleague2)
end
if args.umpirerole2 then
printfd("| umpirerole2 = %s", args.umpirerole2)
end
if args.umpiregames2 then
printfd("| umpiregames2 = %s", args.umpiregames2)
end
if args.umpireyears3 then
printfd("| umpireyears3 = %s", args.umpireyears3)
end
if args.umpireleague3 then
printfd("| umpireleague3 = %s", args.umpireleague3)
end
if args.umpirerole3 then
printfd("| umpirerole3 = %s", args.umpirerole3)
end
if args.umpiregames3 then
printfd("| umpiregames3 = %s", args.umpiregames3)
end
if args.umpireyears4 then
printfd("| umpireyears4 = %s", args.umpireyears4)
end
if args.umpireleague4 then
printfd("| umpireleague4 = %s", args.umpireleague4)
end
if args.umpirerole4 then
printfd("| umpirerole4 = %s", args.umpirerole4)
end
if args.umpiregames4 then
printfd("| umpiregames4 = %s", args.umpiregames4)
end
if args.umpireyears5 then
printfd("| umpireyears5 = %s", args.umpireyears5)
end
if args.umpireleague5 then
printfd("| umpireleague5 = %s", args.umpireleague5)
end
if args.umpirerole5 then
printfd("| umpirerole5 = %s", args.umpirerole5)
end
if args.umpiregames5 then
printfd("| umpiregames5 = %s", args.umpiregames5)
end
printfd("| careerhighlights = %s", args.careerhighlights)
print("}}")
return getBuffer("\n")
end
function p.main(frame)
local args = require("Module:Arguments").getArgs(frame)
return p._main(args)
end
return p