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

Content deleted Content added
No edit summary
Perhaps inelegant, a first attempt at doing _to that works with a-z year specifications.
Line 2:
local p = {}
 
local function items(args, year, oldrange)
local itemList = {}
-- First loop through is to find the lowest year range, if any. If oldrange is supplied, the year range must also be greater than it.
local skipyearrange = nil0;
if args[year .. '_to'] or args[year .. 'a_to'] then
skipyearlocal newrange = tonumber(args[year .. '_to'] or args[year .. 'a_to'])
if newrange and (oldrange == nil or newrange > oldrange) then
range = newrange;
end
end
for asciiletter = 98, 106 do -- 98 > b, 106 > j
if args[year .. string.char(asciiletter) .. '_to'] then
local newrange = tonumber(args[year .. string.char(asciiletter) .. '_to'])
if newrange and (oldrange == nil or newrange > oldrange) and (range == 0 or newrange < range) then
range = newrange;
end
end
end
 
-- Find items, filtered by range if available.
if args[year] or args[year .. 'a'] then
table.insert(itemList,local thisrange = tonumber(args[year .. '_to'] or args[year .. 'aa_to'])
if (emptyyearrange == nil0 and yearcheckthisrange ~== nil) or (emptyyear ~= nilthisrange and yearcheckthisrange == nilrange) then
table.insert(itemList, args[year] or args[year .. 'a'])
end
end
for asciiletter = 98, 106 do -- 98 > b, 106 > j
if args[year .. string.char(asciiletter)] then
table.insert(itemList,local thisrange = tonumber(args[year .. string.char(asciiletter) .. '_to'])
if (range == 0 and thisrange == nil) or (thisrange and thisrange == range) then
table.insert(itemList, args[year .. string.char(asciiletter)])
elseend
end
end
return table.maxn(itemList), itemList, range
end
 
Line 46 ⟶ 71:
end
 
local function left(builder, args, year, itemNum, range)
builder = builder:tag('th')
:attr('scope', 'row')
:css('border-right', '1.4em solid ' .. color(args, year, itemNum))
:wikitext(args[yearrange ..~= '_to']0 and year .. '–' .. args[year .. '_to']range or year)
if itemNum > 1 then
builder = builder:attr('rowspan', itemNum)
Line 85 ⟶ 110:
 
local function row(builder, args, year, emptyyear, lastyear)
local oldrange
local itemNum, itemList = items(args, year)
 
-- If compressempty is set, check for empty items, track empty years, and
-- put out a compressed range when next year is found.
if args.compressempty then
-- If we're compressing and there's no items, return this year for tracking.
if #itemList < 1 then
return year
end
repeat
-- If we have items but are tracking an empty year, output compressed range row.
local itemNum, itemList, range = items(args, year, oldrange)
if emptyyear ~= nil then
builder = builder:tag('tr')
-- If compressempty is set, check for empty items, track empty years, and
if year == 'TBA' then
-- put out a compressed range when next year is found.
left(builder, args, emptyyear .. '–' .. lastyear, 0)
if args.compressempty then
else
-- If we're compressing and there's no items, return this year for tracking.
if year-1 == emptyyear then
if #itemList < 1 then
left(builder, args, emptyyear, 0)
return year
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, range)
else
if year-1 == emptyyear then
left(builder, args, emptyyear .. '–' .. (year-1), 0)
left(builder, args, emptyyear, 0, range)
else
left(builder, args, emptyyear .. '–' .. (year-1), 0, range)
end
end
end
end
end
 
builder = builder:tag('tr')
left(builder, args, year, itemNum, range)
right(builder, itemNum, itemList)
if range ~= 0 then
oldrange = range
end
until range == 0
return nil
Line 158 ⟶ 191:
 
local emptyyear = nil
local skipyear = nil
for year = firstyear, lastyear do
local yearcheck = row(ret, args, year, emptyyear, lastyear)
if skipyear == nil or (skipyear ~= nil and year == skipyear+1) then
if (emptyyear == nil and yearcheck ~= nil) or (emptyyear ~= nil and yearcheck == nil) then
skipyear = nil
emptyyear = yearcheck
local yearcheck = row(ret, args, year, emptyyear, lastyear)
if (emptyyear == nil and yearcheck ~= nil) or (emptyyear ~= nil and yearcheck == nil) then
emptyyear = yearcheck
end
if args[year .. '_to'] then
skipyear = tonumber(args[year .. '_to'])
end
end
end