FANDOM


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 asciiletter = 97, 106 do -- 97 == a, 106 == j
		if args[year .. string.char(asciiletter)] then
			return true
		end
	end
end
 
local function color(args, year)
 
	if args[year .. '_color'] then
		return args[year .. '_color'] 
	end
 
	for yearrange = 1, 5 do
		if args['range' .. yearrange] and args['range' .. yearrange .. '_color'] then
			local _, _, beginyear, endyear = string.find( args['range' .. yearrange], '^(%d%d%d%d).+(%d%d%d%d)$' )
 
			local year = tonumber(year) or 9999 -- For year == 'TBA'
			beginyear = tonumber(beginyear) or 0
			endyear =  tonumber(endyear) or 9999
 
			if year >= beginyear and year <= endyear then
				local _, _, color1, color2 = string.find( args['range' .. yearrange .. '_color'], '^(%S*)%s*(%S*)$' )
				color2 = (color2 == '') and color1 or color2
				return isYearReleased(args, year) and color1 or color2
			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' )
		:css('padding', '5px')
		: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) )
		:css( 'padding', '5px' )
end
 
local function right(builder, args, year)
	if isYearReleased(args, year) == nil then return end
 
	builder = builder:tag('td')
		:css('padding','5px')
	titleItem(builder, args[year] or args[year .. 'a' ])
 
	for asciiletter = 98, 106 do -- 98 == b, 106 == j
		titleItem(builder, args[year .. string.char(asciiletter)])
	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%')
		:css('border-collapse', 'collapse')
		:css('border-spacing', '0')
 
	ret:tag('caption')
		:css('padding', '5px')
		:wikitext(args.title and ('<b>' .. args.title .. '</b>') or '<b>Timeline of release years</b>')
		:wikitext(args.subtitle and ('<br />' .. args.subtitle) )
 
	if tonumber(args.first) then
		firstyear = tonumber(args.first)
	else
		for i = 1940, 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

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.