模組:Release timeline
外观
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function isYearReleased(args, year)
if args[year] then
return true
end
for i = 96, 105 do
if args[year .. string.char(i)] then
return true
end
end
end
local function color(args, year)
return isYearReleased(args, year) and '#0BDA51' or '#228B22'
end
local function titleItem(builder, content)
if content ~= nil then
builder:tag( 'span' ):wikitext( '-' .. content .. '<br />' )
end
end
local function left(builder, year)
local label
if year == 'TBA' then
label = '待定'
else
label = year
end
builder:tag( 'td' ):wikitext( label .. '-' )
end
local function center(builder, args, year)
builder:tag( 'td' )
:css( 'width', '10px' )
:css( 'border', '1px solid black' )
:css( 'background-color', color(args, year) )
end
local function right(builder, args, year)
if isYearReleased(args, year) == nil then return end
builder = builder:tag('td')
titleItem(builder, args[year] or args[year .. 'a' ])
for i = 98, 106 do
titleItem(builder, args[year .. string.char(i)])
end
end
local function row(builder, args, year)
builder = builder:tag('tr')
left(builder, year)
center(builder, args, year)
right(builder, args, year)
end
--------------------------------------------------------------------------------
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
-- Main module code goes here.
local ret
local firstyear, lastyear
ret = mw.html.create( 'table' )
:css('float', args.align or 'right')
:css('clear', args.align or 'right')
:css('margin', '0 0 0.5ex 1em')
:css('font-size', '80%')
:css('line-height', '90%')
:attr('cellspacing', '0')
:attr('cellpadding', '4')
:attr('summary', args.summary or '')
ret:tag('caption')
:css('font-weight', 'bold')
:wikitext(args.title or '发行时间轴')
if tonumber(args.first) then
firstyear = tonumber(args.first)
else
for i = 1980, os.date('%Y') do
if isYearReleased(args, i) then
firstyear = i
break
end
end
end
if tonumber(args.last) then
lastyear = tonumber(args.last)
else
for i = os.date('%Y') + 3, firstyear, -1 do
if isYearReleased(args, i) then
lastyear = i
break
end
end
end
for year = firstyear, lastyear do
row(ret, args, year)
end
row(ret, args, 'TBA')
return ret
end
return p