Module:Release timeline
[voir] [modifier] [historique] [purger]
Module utilisé par le modèle {{Chronologie de sorties par année}}.
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis sa sous-page de documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (créer).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
require('strict')
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function items(args, year)
local itemList = {}
if args[year] or args[year .. 'a'] then
table.insert(itemList, args[year] or args[year .. 'a'])
end
for asciiletter = 98, 106 do -- 98 > b, 106 > j
if args[year .. string.char(asciiletter)] then
table.insert(itemList, args[year .. string.char(asciiletter)])
end
end
return table.maxn(itemList), itemList
end
local function color(args, year, itemNum)
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%d)$' )
local year = tonumber(year) or 9999 -- For year == 'À venir'
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 = string.find(color2, '^#?%w+$') and color2 or color1
return itemNum > 0 and color1 or color2
end
end
end
return itemNum > 0 and '#0BDA51' or '#228B22'
end
local function left(builder, args, year, itemNum, outerPadding)
builder = builder:tag('td')
:attr('scope', 'row')
:css('text-align', 'right') -- For year = 'À venir'
:css('border', 'none')
:css('padding', outerPadding)
:css('border-right', '16px solid ' .. color(args, year, itemNum))
:wikitext(year)
if itemNum > 1 then
builder = builder:attr('rowspan', itemNum)
end
end
local function right(builder, args, year, itemNum, itemList, outerPadding, innerPadding)
if itemNum == 0 then return end
if itemNum == 1 then
builder:tag('td')
:css('padding', outerPadding)
:css('border', 'none')
:wikitext(itemList[1])
return
end
-- if itemNum >= 2
builder:tag('td')
:css('border', 'none')
:css('padding', outerPadding .. ' ' .. outerPadding .. ' ' .. innerPadding)
:wikitext(itemList[1])
for key = 2, itemNum - 1 do
builder = builder:tag('tr')
:tag('td')
:css('border', 'none')
:css('padding', innerPadding .. ' ' .. outerPadding)
:wikitext(itemList[key])
end
builder = builder:tag('tr')
:tag('td')
:css('border', 'none')
:css('padding', innerPadding .. ' ' .. outerPadding)
:wikitext(itemList[itemNum])
end
local function row(builder, args, year, outerPadding, innerPadding)
local itemNum, itemList = items(args, year)
builder = builder:tag('tr')
left(builder, args, year, itemNum, outerPadding)
right(builder, args, year, itemNum, itemList, outerPadding, innerPadding)
end
--------------------------------------------------------------------------------
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
-- Main module code goes here.
local outerPadding, innerPadding = '5px', '2px'
local currentyear = os.date('%Y')
local ret, wikitable
local firstyear, lastyear
local A_venir = items(args, 'À venir') > 0 and true or false
ret = mw.html.create('div')
:css('float', args.align == 'left' and 'left' or 'right')
:css('clear', args.align == 'left' and 'left' or 'right')
:css('margin', args.align == 'left' and '0 1em 0.5ex 0' or '0 0 0.5ex 1em')
wikitable = mw.html.create('table')
:addClass('wikitable')
:css('border', 'none')
:css('font-size', '80%')
:css('line-height', '90%')
:css('border-collapse', 'separate')
:css('border-spacing', '0 1px')
:css('background-color', 'transparent')
wikitable:tag('caption')
:css('padding', outerPadding .. ' ' .. outerPadding .. ' ' .. (args.subtitle and '0px' or innerPadding))
:css('font-size', '112.5%') -- 90% / 80%
:addClass('nowrap')
:wikitext(args.title or 'Chronologie des sorties')
if args.subtitle then
wikitable:tag('tr'):tag('td')
:attr('colspan', '2')
:css('padding', '0px ' .. outerPadding .. ' ' .. innerPadding)
:css('border', 'none')
:css('text-align', 'center')
:wikitext(args.subtitle)
end
if tonumber(args.first) then
firstyear = tonumber(args.first)
else
for i = 1940, currentyear do
if items(args, i) > 0 then
firstyear = i
break
end
end
end
if tonumber(args.last) then
lastyear = tonumber(args.last)
else
for i = currentyear + 3, A_venir and currentyear or firstyear, -1 do
if items(args, i) > 0 then
lastyear = i
break
end
end
lastyear = lastyear or (currentyear - 1)
end
for year = firstyear, lastyear do
row(wikitable, args, year, outerPadding, innerPadding)
end
if A_venir then
row(wikitable, args, 'À venir', outerPadding, innerPadding)
end
ret:node(wikitable)
if args['légende'] then
ret:tag('div')
:wikitext('Légende')
:css('font-weight', 'bold')
:css('font-size', '90%')
:css('text-align', 'center')
ret:tag('div')
:wikitext(args['légende'])
:css('font-size', '90%')
:css('padding-left', '1.5em')
end
return ret
end
return p