Jump to content

Module:Jcon

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Happy5214 (talk | contribs) at 07:50, 25 March 2014 (Creating migration module). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}
local insert = table.insert

local jctTypeData = {["Hwy"] = "Hwy", ["Highway"] = "Hwy", ["Sudbury"] = "MR",
                     ["SB"] = "MR", ["Greater Sudbury"] = "MR", ["GS"] = "MR",
                     ["Muskoka"] = "DR", ["Durham"] = "RR", ["Hamilton"] = "RR",
                     ["Halton"] = "RR", ["Niagara"] = "RR", ["Peel"] = "RR",
                     ["Ottawa"] = "RR", ["Waterloo"] = "RR", ["York"] = "RR",
                     ["KL"] = "KLR", ["Kawartha Lakes"] = "KLR", ["Durham Regional Highway"] = "RR",
                     ["DRH"] = "RR"}

local regionData = {Hwy = '', Highway = ''}

function p.jcon(frame)
	local args = frame:getParent().args
	local type = args[1] or ''
	if type == '' then return end
	local route1 = args[2] or ''
	if route1 == '' then return end
	local route2 = args.con or ''
	local route3 = args.con2 or ''
	local jctType = jctTypeData[type] or 'CR'
	local region = regionData[type] or type
	local jctCall = {"{{jct", "province=ON", jctType, route1}
	if region ~= '' then
		insert(jctCall, "county=" .. region)
	end
	if route2 ~= '' then
		insert(jctCall, jctType)
		insert(jctCall, route2)
	end
	if route3 ~= '' then
		insert(jctCall, jctType)
		insert(jctCall, route3)
	end
	-- Add direction and location stuff
	return table.concat(jctCall, "|") .. "}}"
end

return p