Jump to content

Module:Jcon

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by BrandonXLF (talk | contribs) at 21:51, 18 October 2018. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}
local getArgs = require("Module:Arguments").getArgs
local data = mw.loadData('Module:Jcon/data')                                    -------------------- ADD PICTURE RULES, TYPES, REGION ALIAS AND OTHER PICTURES AT MODULE:JCON/DATA
local miscTable = data.miscTable
local typeTable  = data.typeTable
local altDivTable = data.altDivTable
local pictureTable = data.pictureTable

--[[ 
          R E T U R N P I C T U R E C O R E
          Return the picture of text 
]]--

local function returnPictureCore(frame,Type,args,division)
	local export = ""
	if not pictureTable[division] then
		return ""
	end
	
	local picture = pictureTable[division][1]..args[2]..pictureTable[division][2] or ""
	if args[2] == "52" and division == "Simcoe" then                            -------------------- ADD PICTURE EXCEPTIONS RULES HERE
		export = "Simcoe county road 52.png"
	elseif args[2] == "407ETR" and division == "Highway" then
		export = "Highway407crest.png"
	elseif args[2] == "QEW" and division == "Highway" then
		export = "Ontario QEW.svg"
	elseif tonumber((string.gsub(args[2],"%D",""))) >= 500 then
		export = "Ontario Highway "..args[2]..".svg"
	else  
		export = picture  
	end
	if frame:callParserFunction('#ifexist', 'Media:' .. export, '1') ~= '' then
		if args["size"] then                                                    -------------------- ADD PICTURE SIZES HERE
			return table.concat({"[[File:",export,"|alt=|link=|",args["size"],"]]"})
		elseif division == "Highway" then
			return table.concat({"[[File:",export,"|alt=|link=|24x22px]]"})
		elseif division == "Kawartha Lakes" then
			return table.concat({"[[File:",export,"|alt=|link=|21px]]"})
		else
			return table.concat({"[[File:",export,"|alt=|link=|19px]]"})
		end
	else
		return ""
	end
end

--[[
          R E T U R N P I C U T R E 
          Return unnil version of returnPictureCore 
--]]

local function returnPicture(frame,Type,args,division)
	local export = returnPictureCore(frame,Type,args,division) 
	
	if export == nil then
		export =""
	end
	
	return export
end

--[[
          R E T U R N T E X T 
          Returns the text/link 
]]--

local function returnText(frame,Type,args,division)
	local export;
	local dis;
	
	if not args["nolink"] then                                                  -------------------- ADD LINKS HERE
		if args[2] == "407ETR" then --EXCEPTION
			export = "Ontario Highway".." ".."407"
			dis = "Highway".." ".."407"
		elseif args[2] == "QEW" then --EXCEPTION
			export = "Queen Elizabeth Way"
		elseif Type == "Highway" then
			export = "Ontario Highway".." "..args[2]
			dis = "Highway".." "..args[2]
		elseif Type == "Regional Highway" then
			export = division.." Regional Highway".." "..args[2]
		elseif Type == "County Highway" then
			export = division.." County Highway".." "..args[2]
		else 
			local Type2;
			if division == "Kawartha Lakes" then 
				Type2 = "" 
			else
				Type2 = " "..Type
			end
			export = division..Type2.." ".."Road".." "..args[2]
			dis = Type.." ".."Road".." "..args[2]
		end
		if frame:callParserFunction('#ifexist',export, '1') ~= '' then
			if dis then
				export =  "[["..export.."|"..dis.."]]"
			else
				export = "[["..export.."]]"
			end
		elseif dis then
			export = dis
		end
	end
	
	if not export then                                                          -------------------- ADD NON-LINKS HERE
		if args[2] == "407ETR" then --EXCEPTION
			export = "Highway".." ".."407"
		elseif args[2] == "QEW" then --EXCEPTION
			export = "Queen Elizabeth Way"
		elseif Type == "Highway" then
			export = "Highway".." "..args[2]
		elseif Type == "Regional Highway" then
			export = division.."Regional Highway".." "..args[2]
		elseif Type == "County Highway" then
			export = division.."County Highway".." "..args[2]
		else 
			export = Type.." ".."Road".." "..args[2]
		end
	end
	
	return export
end

--[[
           A D D P L A C E 
           Add name/link for a city/town
]]--

local function addPlace(frame,export,place,after)
	local preExport
	if frame:callParserFunction('#ifexist',place..", Ontario", '1') ~= '' then
		preExport = "[["..place..", Ontario|"..place.."]]"
	else
		preExport = place
	end
	if after == true then
		return export..", "..preExport
	else
		return export.." – "..preExport
	end
end

--[[
           P . J C O N
           Return final picture(s)/text(s)
]]--

function p.jcon (frame)
	local args = getArgs(frame)
	local Type = typeTable[args[1]]
	local division = altDivTable[args[1]] or args[1]
	local export = ""
	
	args[1] = args[1] or ""
	args[2] = args[2] or ""
	
	if miscTable[args[1]:lower()] or miscTable[args[2]:lower()] then
		return miscTable[args[1]:lower()] or miscTable[args[2]:lower()]
	end
	
	if not typeTable[args[1]] then
		return "​"
	end
	
	if args[2] == "" then
		return "​"
	end
	
	if args["ot"] then
		args["nosh"] = "yes"
		args["nolink"] = "yes"
	end
	
	args["2A"] = args[2]
	if args["con"] then args["2B"] = args["con"] end
	if args["con2"] then args["2C"] = args["con2"] end
	
	if not args["nosh"] then
		args[2] = args["2A"]
		picture = returnPicture(frame,Type,args,division)
		
		if args["con"] then
			args[2] = args["2B"]
			picture = picture.." "..returnPicture(frame,Type,args,division)
		end
		
		if args["con2"] then
			args[2] = args["2C"]
			picture = picture.." "..returnPicture(frame,Type,args,division) 
		end

		if picture ~= "" then
			picture = picture.." "
		end
	end
	
	if not args["pic_aft"] then
		export = picture
	end
	
	if not args["notext"] then 
		args[2] = args["2A"]
		export = export..returnText(frame,Type,args,division) 
		
		if args["con"] then
			args[2] = args["2B"]
			export = export.." ".."/".." "..returnText(frame,Type,args,division)
		end
		
		if args["con2"] then
			args[2] = args["2C"]
			export = export.." ".."/".." "..returnText(frame,Type,args,division)
		end
	end
		
	if args["dir"] then -- Direction
		export = export.." "..args["dir"]
		if args["condir"] then
			export=export.."/"..args["condir"]
		end
	end
	
	if args[3] then -- Name (argument 3)
		export = export.." ("..args[3]..")"
	end
	
	if args["city"] then -- City 1
		export = addPlace(frame,export,args["city"],false)
	elseif args["town"] then -- Or town 1
		export = addPlace(frame,export,args["town"],false)
	end
		
	if args["city2"] then -- City 1
		export = addPlace(frame,export,args["city2"],true)
	elseif args["town2"] then -- Or town 1
		export = addPlace(frame,export,args["town2"],true)
	end
	
	if args["pic_aft"] then
		export = export..picture
	end
	
	return export
end

--[[
           P . S U P P O R T E D 
           Return all supported "regions" in a list format
]]--

function p.supported (frame)
	local export = "<u>'''Supported 'Regions''''</u>"
	for k,v in pairs(typeTable) do
		export = export.."<br /> • "..k
	end
	for k,v in pairs(miscTable) do
		export = export.."<br /> • "..k
	end
	return export
end

--[[
           Return Output
           End of module
]]--

return p;