Difference between revisions of "Module:Navseasoncats/navyear/sandbox"

From blackwiki
Jump to navigation Jump to search
blackwiki>Tom.Reding
(check arg4 more)
blackwiki>Tom.Reding
m (alt)
Line 10: Line 10:
 
local arg2 = tonumber(frame.args[2])
 
local arg2 = tonumber(frame.args[2])
 
local arg3 = frame.args[3]
 
local arg3 = frame.args[3]
local arg4 = frame.args[4]
+
local arg4 = tonumber(frame.args[4])
if arg4 and arg4 ~= '' then tonumber(arg4)
+
if arg4 == nil then arg4 = -9999 end
else arg4 = -9999 end
 
 
 
 
local navyear = '{| class="toccolours hlist" style="text-align: center; margin: auto;"\n' .. '|\n'
 
local navyear = '{| class="toccolours hlist" style="text-align: center; margin: auto;"\n' .. '|\n'

Revision as of 15:09, 2 November 2018

Documentation for this module may be created at Module:Navseasoncats/navyear/sandbox/doc

local p = {}

function p.navyear(frame)
	--Expects a PAGENAME of the form "Some sequential 2015 example cat", where 
	--	{{{1}}}=Some sequential
	--	{{{2}}}=2015
	--	{{{3}}}=example cat
	--	{{{4}}}=1758 ('minumum year' parameter; optional)
	local arg1 = frame.args[1]
	local arg2 = tonumber(frame.args[2])
	local arg3 = frame.args[3]
	local arg4 = tonumber(frame.args[4])
	if arg4 == nil then arg4 = -9999 end
	
	local navyear = '{| class="toccolours hlist" style="text-align: center; margin: auto;"\n' .. '|\n'
	
	local i = -5
	while i <= 5 do
		local year = arg2 + i
		if i ~= 0 then
			if year < arg4 then
				navyear = navyear..'*<span style="visibility:hidden">'..year..'</span>\n'
			else
				navyear = navyear..'*'..frame:expandTemplate{ title = 'LinkCatIfExists2', args = { arg1..' '..year..' '..arg3, year } }..'\n'
			end
		else
			navyear = navyear..'*<b>'..arg2..'</b>\n'
		end
		i = i + 1
	end
	return navyear..'|}'
end

return p