Module:Timeline of release years/sandbox: Difference between revisions

Content deleted Content added
Actually we can use the new range parameter for this. Which means we can stop checking the length of years from compressempty
Simplifications
 
(8 intermediate revisions by 3 users not shown)
Line 1:
require('Module:No globalsstrict')
local p = {}
 
Line 40:
end
 
local function color(args, year, itemNum, to_range)
 
if args[year .. '_color'] then
return args[year .. '_color']
end
if to_range and args[year .. '_to_' .. to_range .. '_color'] then
return args[year .. '_to_' .. to_range .. '_color']
end
 
Line 68 ⟶ 72:
builder = builder:tag('th')
:attr('scope', 'row')
:css('border-right', '1.4em solid ' .. color(args, year, itemNum, range))
:wikitext(range ~= 0 and year .. '–' .. range or year)
if itemNum > 1 then
builder = builder:attr('rowspan', itemNum)
end
if year == 'TBA' then
builder:tag('abbr'):attr('title', 'To be announced'):wikitext('TBA')
else
builder:wikitext(range ~= 0 and year .. '–' .. range or year)
end
end
Line 103 ⟶ 111:
end
 
local function row(builder, args, year, emptyyear, lastyear, highrange)
local oldrange = nil
Line 109 ⟶ 117:
local itemNum, itemList, range = items(args, year, oldrange)
-- Now check for a new high range and catch it. We need to know what highrange was prior to update though.
-- If compressempty is set, check for empty items, track empty years, and
local oldhighrange = nil
if(range > 0 and (highrange == nil or range > highrange)) then
oldhighrange = (highrange or range)
highrange = range
end
oldhighrange = (oldhighrange or highrange)
 
-- If compressempty is set, check for empty items, track empty years and high ranges, and
-- put out a compressed range when next year is found.
if args.compressempty and oldrange == nil then
-- If we're compressing and there's no items, return this year for tracking.
if #itemList < 1 then
return year, highrange
end
 
-- If emptyyear is below or equal the highrange, we need to make adjustments.
if(emptyyear and oldhighrange and emptyyear <= oldhighrange) then
-- If the current year is highrange or highrange +1, suppress empty row output entirely.
-- If the current year is highrange+2 or more, adjust the emptyyear to be above highrange)
if(year <= (oldhighrange+1)) then
emptyyear = nil
elseif(year > (oldhighrange+1)) then
emptyyear = oldhighrange+1
end
end
 
-- If we have items but are tracking an empty year, output compressed range row.
if emptyyear ~= nil then
Line 122 ⟶ 149:
if year == 'TBA' then
left(builder, args, emptyyear, 0, lastyear)
elseif year-1 == emptyyear then
left(builder, args, emptyyear, 0, 0)
else
ifleft(builder, year-1 ==args, emptyyear, then0, year-1)
left(builder, args, emptyyear, 0, 0)
else
left(builder, args, emptyyear, 0, year-1)
end
end
end
Line 146 ⟶ 171:
until range == 0
return nil, highrange
end
 
Line 155 ⟶ 180:
local ret
local firstyear, lastyear
local TBA = items(args, 'TBA') > 0 and true or false
 
ret = mw.html.create( 'table' )
Line 190 ⟶ 215:
 
local emptyyear = nil
local highrange = nil
for year = firstyear, lastyear do
local yearcheck, newhighrange = row(ret, args, year, emptyyear, lastyear, highrange)
if (emptyyear == nil and yearcheck ~= nil) or (emptyyear ~= nil and yearcheck == nil) then
emptyyear = yearcheck
end
highrange = newhighrange
end