Content deleted Content added
move styles to _main, local for module:arguments rename classes because I'm bothered by underscore names which are not quite entirely unconventional, move caption class off to css, retarget tstyles to module version |
Implement new ranging function for items that span years. |
||
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 range = 0;
if args[year .. '_to'] or args[year .. 'a_to'] then
local 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
if (range == 0 and thisrange == nil) or (thisrange and thisrange == range) 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
if (range == 0 and thisrange == nil) or (thisrange and thisrange == range) then
table.insert(itemList, args[year .. string.char(asciiletter)])
end
end
return table.maxn(itemList), itemList, range
end
local function color(args, year, itemNum, to_range)
if args[year .. '_color'] then
Line 21 ⟶ 46:
end
if to_range and args[year .
return args[year .. '_to_' .. to_range .. '_color']
▲ end
end
Line 46 ⟶ 69:
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, range))
:wikitext(range ~= 0 and year .. '–' .. range or year)
if itemNum > 1 then
builder = builder:attr('rowspan', itemNum)
Line 84 ⟶ 107:
end
local function row(builder, args, year, emptyyear, lastyear, highrange)
local
-- 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')▼
-- Now check for a new high range and catch it. We need to know what highrange was prior to update though.
if year == 'TBA' then▼
local oldhighrange = nil
left(builder, args, emptyyear .. '–' .. lastyear, 0)▼
if(range > 0 and (highrange == nil or range > highrange)) then
▲ else
oldhighrange = (highrange or range)
if year-1 == emptyyear then▼
highrange = range
left(builder, args, emptyyear, 0)▼
end
oldhighrange = (oldhighrange or highrange)
▲ -- 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
else
▲ if year-1 == emptyyear then
left(builder, args, emptyyear .. '–' .. (year-1), 0)▼
▲ left(builder, args, emptyyear, 0, 0)
else
end
end
end
end
▲ end
-- We can break out if this is the case. This means we have looped through more than once, but there were no more items remaining.
if range == 0 and oldrange and #itemList < 1 then
break
end
if range ~= 0 then
oldrange = range
end
until range == 0
return nil, highrange
end
Line 158 ⟶ 213:
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
|