Module:Infobox road/link/CAN

local p = {}

local format = mw.ustring.format

local typesModule = require "Module:Infobox road/link/defs" Country = typesModule.Country Type = typesModule.Type Link = typesModule.Link

local links = Country:new do -- Link definitions function links:typeOverride(args) local type = args.type local province = args.province if type == province then return self["Hwy"] else return nil end end function links:link(args) local type = self:type(args) return type and (type:link(args) .. self:dab(args)) or error("Invalid type", 0) end function links:dab(args) local dabArg = args.dab return dabArg and format(" (%s)", dabArg) or "" end do -- Provincial highways local type = Type:new do           local types = {"Fwy", "Hwy", "PTH", "Route", "TCH"} for i,v in ipairs(types) do               links[v] = type end end type["AB"] = Link:new{formatStr = "Alberta Highway %s"} type["BC"] = Link:new{formatStr = "British Columbia Highway %s"} type["MB"] = Link:new{formatStr = "Manitoba Highway %s"} type["NB"] = Link:new{formatStr = "New Brunswick Route %s"} type["NL"] = Link:new{formatStr = "Newfoundland and Labrador Route %s"} type["ON"] = Link:new{formatStr = "Ontario Highway %s", exceptions={["QEW"] = "Queen Elizabeth Way"}} type["PE"] = Link:new{formatStr = "Prince Edward Island Route %s"} type["QC"] = Link:new{formatStr = "Quebec Route %s"} type["SK"] = Link:new{formatStr = "Saskatchewan Highway %s"} do -- Nova Scotia local function processTypeExceptions(exceptions, default, formatArgs) return function (args) local formatArguments = {} for i,v in ipairs(formatArgs) do                       formatArguments[i] = args[v] end local type = args.type local formatStr = exceptions[type] or default args.override = format(formatStr, unpack(formatArguments)) end end local typeExceptions = {["Hwy"] = "Nova Scotia Highway %s", ["NS"] = "Nova Scotia Highway %s", ["TCH"] = "Nova Scotia Highway %s", ["PTH"] = "Nova Scotia Highway %s", ["Route"] = "Nova Scotia Route %s"} local preprocessor = processTypeExceptions(typeExceptions, '', {"route"}) type["NS"] = Link:new{formatStr = "%s", formatArgs = {"override"}, preprocessors = {preprocessor}} end -- Nova Scotia end -- Provincial highways do -- Autoroutes local link = Link:new{formatStr = "Quebec Autoroute %s"} links["Autoroute"] = link links["A"] = link end -- Autoroutes links["MR"] = Link:new{formatStr = "%s Road %s", formatArgs = {"county", "route"}} -- Municipal roads do -- Secondary Highways local type = Type:new{["ON"] = Link:new{formatStr = "Ontario Highway %s"}} links["Sec"] = type links["Secondary"] = type end -- Secondary Highways links["CR"] = Link:new{formatStr = "%s County Road %s", formatArgs = {"county", "route"}} -- County roads links["RR"] = Link:new{formatStr = "%s Regional Road %s", formatArgs = {"county", "route"}} -- Regional roads links["Trunk"] = Type:new{["NS"] = Link:new{formatStr = "Nova Scotia Trunk %s"}} -- Trunk highways links["PR"] = Link:new{formatStr = "Manitoba Provincial Road %s"} -- Provincial roads end

p.links = links return p