پودمان:Infobox college coach/convert
از پژوهشکده امر به معروف
توضیحات این پودمان میتواند در پودمان:Infobox college coach/convert/توضیحات قرار گیرد.
-- [SublimeLinter luacheck-globals:mw]
-- This module serves to convert <br>-delimited teams/years parameters in
-- [[Template:Infobox college coach]] to their equivalent numbered pairs. Simply
-- replace "{{Infobox college coach" with
-- "{{subst:#invoke:Infobox college coach/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(prefix, teams, years)
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)
if #newTeams ~= #newYears then
printfd("<!-- Template:Infobox college coach conversion error: " ..
"%s_teams and %s_years are not of equal length. -->",
prefix, prefix)
printfd("| %s_teams = %s", prefix, teams)
printfd("| %s_years = %s", prefix, years)
return
end
c = 1
for i = 1, #newTeams do
if newYears[i] ~= "" or newTeams[i] ~= "" then
if newTeams[i] == "" then
printfd("| %s_sport%s = %s", prefix, c,
string.match(newYears[i], "^'*(.-)'*$"))
elseif newYears[i] == "" then
printfd("| %s_sport%s = %s", prefix, c,
string.match(newTeams[i], "^'*(.-)'*$"))
else
printfd("| %s_years%s = %s", prefix, c, newYears[i])
printfd("| %s_team%s = %s", prefix, c, newTeams[i])
end
c = c + 1
end
end
end
function p._main(args)
print("{{Infobox college coach")
printfd("| name = %s", args.name)
printfd("| image = %s", args.image)
if args.image_upright then
printfd("| image_upright = %s", args.image_upright)
end
printfd("| alt = %s", args.alt)
printfd("| caption = %s", args.caption)
printfd("| sport = %s", args.sport)
if args.current_title or args.current_team or args.current_conference
or args.current_record or args.contract then
printfd("| current_title = %s", args.current_title)
printfd("| current_team = %s", args.current_team)
printfd("| current_conference = %s", args.current_conference)
printfd("| current_record = %s", args.current_record)
printfd("| contract = %s", args.contract)
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)
printfd("| alma_mater = %s", args.alma_mater)
if args.player_teams and args.player_years then
processTeamsYears("player", args.player_teams, args.player_years)
elseif args.player_teams then
print("<!-- Template:Infobox college coach conversion error: " ..
"Template has player_teams but no player_years. -->")
printfd("| player_teams = %s", args.player_teams)
print("| player_years = ")
elseif args.player_years then
print("<!-- Template:Infobox college coach conversion error: " ..
"Template has player_years but no player_teams. -->")
print("| player_teams = ")
printfd("| player_years = %s", args.player_years)
end
if args.player_positions then
printfd("| player_positions = %s", args.player_positions)
end
if args.coach_teams and args.coach_years then
processTeamsYears("coach", args.coach_teams, args.coach_years)
elseif args.coach_teams then
print("<!-- Template:Infobox college coach conversion error: " ..
"Template has coach_teams but no coach_years. -->")
printfd("| coach_teams = %s", args.coach_teams)
print("| coach_years = ")
elseif args.coach_years then
print("<!-- Template:Infobox college coach conversion error: " ..
"Template has coach_years but no coach_teams. -->")
print("| coach_teams = ")
printfd("| coach_years = %s", args.coach_years)
end
if args.admin_teams and args.admin_years then
processTeamsYears("admin", args.admin_teams, args.admin_years)
elseif args.admin_teams then
print("<!-- Template:Infobox college coach conversion error: " ..
"Template has admin_teams but no admin_years. -->")
printfd("| admin_teams = %s", args.admin_teams)
print("| admin_years = ")
elseif args.admin_years then
print("<!-- Template:Infobox college coach conversion error: " ..
"Template has admin_years but no admin_teams. -->")
print("| admin_teams = ")
printfd("| admin_years = %s", args.admin_years)
end
printfd("| overall_record = %s", args.overall_record)
printfd("| bowl_record = %s", args.bowl_record)
printfd("| tournament_record = %s", args.tournament_record)
if args.CFbDWID then
printfd("| CFbDWID = %s", args.CFbDWID)
end
printfd("| championships = %s", args.championships)
printfd("| awards = %s", args.awards)
printfd("| coaching_records = %s", args.coaching_records)
if args.CFBHOF_year then
printfd("| CFBHOF_year = %s", args.CFBHOF_year)
end
if args.BASKHOF_year then
printfd("| BASKHOF_year = %s", args.BASKHOF_year)
end
if args.CBBASKHOF_year then
printfd("| CBBASKHOF_year = %s", args.CBBASKHOF_year)
end
if args.CBASEHOF_year then
printfd("| CBASEHOF_year = %s", args.CBASEHOF_year)
end
if args.CFBHOF_id then
printfd("| CFBHOF_id = %s", args.CFBHOF_id)
end
if args.BASKHOF_id then
printfd("| BASKHOF_id = %s", args.BASKHOF_id)
end
if args.medaltemplates then
printfd("| medaltemplates = %s", args.medaltemplates)
end
if args["show-medals"] then
printfd("| show-medals = %s", args["show-medals"])
end
print("}}")
return getBuffer("\n")
end
function p.main(frame)
local args = require("Module:Arguments").getArgs(frame)
return p._main(args)
end
return p






