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

Content deleted Content added
Inactive years shouldn't use a range, period. Because we're looping over this repeatedly now, we also need to make sure compressempty only processes on the first loop, when oldrange is nil. Also, on the second+ loop, there may not be any items left to output. Avoid outputting a false inactive row.
Simplifications
 
(9 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
Line 46:
end
if to_range and args[year .compressempty. '_to_' .. to_range .. '_color'] then
return args[year .. '_to_' .. to_range .. '_color']
if(string.len(year) > 4) then
year = string.sub(year,1,4)
end
end
 
Line 74 ⟶ 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 109 ⟶ 111:
end
 
local function row(builder, args, year, emptyyear, lastyear, highrange)
local oldrange = nil
Line 115 ⟶ 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
builder = builder:tag('tr')
if year == 'TBA' then
left(builder, args, emptyyear .. '–' .. lastyear, 0, 0lastyear)
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 .. '–' .. (year-1), 0, 0)
end
end
end
Line 152 ⟶ 171:
until range == 0
return nil, highrange
end
 
Line 161 ⟶ 180:
local ret
local firstyear, lastyear
local TBA = items(args, 'TBA') > 0 and true or false
 
ret = mw.html.create( 'table' )
Line 196 ⟶ 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