Przejdź do zawartości

Moduł:Okres geologiczny

Z Wikipedii, wolnej encyklopedii
 Dokumentacja modułu [stwórz] [odśwież]
local function periodData(frame)
	local pf = frame:getParent();
	local period = frame.args[1] or pf.args[1]
	if period then
		local shift =  frame.args[2] or pf.args[2]
		local data = mw.loadData("Moduł:Okres geologiczny/data")
		local item = data[mw.ustring.lower(period)]
		if type(item) == "string" then
			period = item
			item = data[period]
		end
		
		if type(item) == "table" then
			if shift == nil then
				return period, item
			elseif shift == "+1" then
				return item.next, data[item.next] or item.next, shift
			elseif shift == "-1" then
				return item.prev, data[item.prev] or item.prev, shift
			else
				error("Nieobsługiwany parametr shift='"..shift.."'")
			end	
		end
	
		return period
	end
end

return {
	
["Okres"] = function (frame)
	local period, data, _ = periodData(frame)
	if type(data) == "table" then
		return period
	end
end,

["Kolor"] = function (frame)
	local _, data, _ = periodData(frame)
	local alpha = frame.args.alpha or frame:getParent().args.alpha or "100%"
	if (type(data) == "table") and data.rgb then
		return "rgba("..data.rgb..","..alpha..")"
	end
end,

["Link"] = function (frame)
	local period, data, _ = periodData(frame)
	local link = type(data) == "table" and data.link or false
	return link or period
end,

["Artykuł"] = function (frame)
	local period, data, _ = periodData(frame)
	local link = false
	if (type(data) == "table") and data.link then
		link = mw.ustring.match(data.link, "%[%[([^%]|]+)")
	end

	return link or period
end,

["Start"] = function (frame)
	local _, data, _ = periodData(frame)
	if (type(data) == "table") and data.start then
		return data.start
	end
end,

}