Module:Timeline of release years
Appearance
Related pages |
---|
![]() | This module depends on the following other modules: |
![]() | This module uses TemplateStyles: |
This module implements {{Timeline of release years}}.
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 = 97, 106 do
if args[year .. string.char(i)] then
return true
end
end
end
local function color(args, year)
if args[year .. '_color'] then
return args[year .. '_color']
end
for i = 1, 5 do
if args['range' .. i] then
local _, _, beginyear, endyear = string.find( args['range' .. i], '^(%d%d%d%d).+(%d%d%d%d)$' )
year = tonumber(year)
beginyear = tonumber(beginyear) or 0
endyear = tonumber(endyear) or 0
if year >= beginyear and year <= endyear then
return args['range' .. i .. '_color']
end
end
end
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)
builder:tag( 'td' )
:attr('align', 'right')
:wikitext( year .. ' –' )
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, TBA
TBA = isYearReleased(args, 'TBA')
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 'Timeline of release years')
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, TBA and os.date('%Y') or firstyear, -1 do
if isYearReleased(args, i) then
lastyear = i
break
end
end
lastyear = lastyear or (os.date('%Y') - 1)
end
for year = firstyear, lastyear do
row(ret, args, year)
end
if TBA then
row(ret, args, 'TBA')
end
return ret
end
return p