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.
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
-- Find items, filtered by range if available.
if args[year] or args[year .. 'a'] 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
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(
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.▼
if emptyyear ~= nil then▼
builder = builder:tag('tr')▼
if year == 'TBA' then▼
left(builder, args, emptyyear .. '–' .. lastyear, 0)▼
▲ 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
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
if (emptyyear == nil and yearcheck ~= nil) or (emptyyear ~= nil and yearcheck == nil) then
▲ 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
|