Module:Team appearances list: Difference between revisions

Content deleted Content added
f
Automate greying out of absences
Line 3:
-- [[<team> at the <year> <competition>|<year]]. The module requires the
-- following parameters: begin_year, interval, team and competition. end_year
-- may be optionally defined if either the sports competition or the team is now
-- defunct. FurtherAdditionally, any number of positional parameters may be specified; these,
-- each of which must be a year (or year range) in which the team was absent
-- will be added to the front of the list.
-- from the competition.
 
local p = {}
local compressSparseArray = require('Module:TableTools').compressSparseArray
local hlist = require('Module:List').horizontal
local valueUnion = require('Module:Set').valueUnion
 
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {parentOnly = true})
return p._main(args)
end
function p._main(args)
local appearances = compressSparseArray(args){}
local absences = {}
for _, v in pairs(compressSparseArray(args)) do
absences[mw.ustring.sub(v, 1, 4)] = mw.getCurrentFrame():expandTemplate{
title='Gray', args={v}}
end
 
for i = args.begin_year, (args.end_year or os.date('%Y')+args.interval),
args.interval do
if absences[tostring(i)] then
table.insert(appearances, mw.ustring.format('[[%s at the %s %s|%s]]',
table.insert(appearances, absences[tostring(i)])
args.team, i, args.competition, i))
absences[tostring(i)] = nil
else
table.insert(appearances, mw.ustring.format('[[%s at the %s %s|%s]]',
'[[%s at the %s %s|%s]]', args.team, i, args.competition, i))
end
end
return hlist(valueUnion(absences, appearances))
end