Módulo:Linha do tempo anual

Fonte: Enciclopédia de conhecimento da Igreja de Deus
Saltar para a navegação Saltar para a pesquisa

A documentação para este módulo pode ser criada na página Módulo:Linha do tempo anual/doc

--Adaptação de Module:Release_timeline anglófono
-- https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual
-- http://tylerneylon.com/a/learn-lua/
require('strict')
local getArgs = require('Module:Arguments').getArgs
local p = {}
local function emptyRow (tableElement)
	local tr = tableElement:tag('tr')
	tr:tag('td'):css('border', 'none')
	tr:tag('td'):css('border', 'none')
	tr:tag('td'):css('border', 'none')
end
local function readArgs (args)
	local keysByYear = {}
	local itemByKey = {}
	for key, value in pairs(args) do
		if string.find(key, '^%d%d%d%d') then
			local _, _, isodate, year, month, day, color = string.find(key, '^((%d%d%d%d)-?(%d?%d?)-?(%d?%d?))%s?(%S*)$')
			itemByKey[key] = {
				text = value,
				color = color ~= '' and color or 'transparent',
				date = mw.language.getContentLanguage():formatDate(day ~= '' and '[[d "de" F]]' or '[[F]]', isodate)
			}
			keysByYear[year] = keysByYear[year] or {}
			keysByYear[year][key] = true
		end
	end
	return keysByYear, itemByKey, args.titulo or 'Linha do tempo'
end
local function iSortedKeys (atable)
	local keys = {}
	for key in pairs(atable) do table.insert(keys, tostring(key)) end
	table.sort(keys)
	return ipairs(keys)
end
local function tableSize (atable)
		local size = 0
		for _ in pairs(atable) do size = size + 1 end
		return size
end
--------------------------------------------------------------------------------
function p.main(frame)
	local args = getArgs(frame)
	local keysByYear, itemByKey, title = readArgs(args)
	local tableElement = mw.html.create('table')
		:addClass('wikitable')
		:css('border-collapse', 'separate')
	tableElement:tag('caption'):wikitext(title)
	emptyRow(tableElement)
	for i, year in iSortedKeys(keysByYear) do
		local keys = keysByYear[year]
		local yearRowElement = tableElement:tag('tr')
		yearRowElement:tag('td')
			:attr('scope', 'row')
			:attr('rowspan', tableSize(keys) + 1)
			:css('border', 'none')
			:css('border-right', '1px solid gray')
			:css('vertical-align', 'top')
			:wikitext(year)
		yearRowElement:tag('td')
			:css('display', 'none')
		for i, key in iSortedKeys(keys) do
			local tr = tableElement:tag('tr')
			tr:tag('td')
				:css('border', 'none')
				:css('text-align', 'right')
				:css('vertical-align', 'top')
				:css('width', '120px')
				:wikitext(itemByKey[key].date)
			tr:tag('td')
				:css('border', 'none')
				:css('border-left', '16px solid ' .. itemByKey[key].color)
				:wikitext(itemByKey[key].text)
		end
		emptyRow(tableElement)
	end
	return tableElement
end
return p