Module:Infobox road/link

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 = {} do function links:link(args) local countryArg = args.country local success, country = pcall(self.country, self, countryArg) if not(success) then return '' else local success, link = pcall(country.link, country, args) if success then return link elseif link == 'Invalid type' then local page = mw.title.getCurrentTitle local pagename = page.prefixedText local ns = page.namespace return (ns == 0) and format("", pagename) or error(link, 0) else error(link, 0) end end end function links:country(name) local link = self[name] if link then return link end local module = require(format("Module:Infobox road/link/%s", name)) return module.links end links.BGD = Country:newWithSimpleLinks{["N"] = "N%s (Bangladesh)", ["R"] = "R%s (Bangladesh)", ["Z"] = "Z%s (Bangladesh)"} -- Bangladesh links.CHE = Country:newWithSimpleLinks{["A"] = "A%s motorway (Switzerland)"} -- Switzerland links.CHL = Country:newWithSimpleLinks{["CH"] = "Chile Route %s"} -- Chile links.CYP = Country:newWithSimpleLinks{["A"] = "A%s motorway (Cyprus)", ["B"] = "B%s road (Cyprus)"} -- Cyprus links.CZE = Country:newWithSimpleLinks{["D"] = "D%s motorway (Czech Republic)", ["R"] = "R%s expressway (Czech Republic)"} -- Czech Republic links.DEU = Country:newWithSimpleLinks{["A"] = "Bundesautobahn %s", ["B"] = "Bundesstraße %s"} -- Germany links.ESP = Country:newWithSimpleLinks{["A"] = "Autovía A-%s", ["E"] = "European route E%s", ["M"] = "Autopista M-%s", ["R"] = "R-%s motorway (Spain)"} -- Spain links.EUR = Country:newWithSimpleLinks{["E"] = "European route E%s"} -- Europe links.GEO = Country:newWithSimpleLinks{["A"] = "S%s highway (Georgia)", ["B"] = "Sh%s road (Georgia)"} -- Georgia links.GRC = Country:newWithSimpleLinks{["A"] = "Motorway %s (Greece)", ["EO"] = "Greek National Road %s"} -- Greece links.HKG = Country:newWithSimpleLinks{[{"Route", "route"}] = "Route %s (Hong Kong)"} -- Hong Kong links.HRV = Country:newWithSimpleLinks{["A"] = "A%s (Croatia)", ["D"] = "D%s (Croatia)"} -- Croatia links.HUN = Country:newWithSimpleLinks{["M"] = "M%s motorway (Hungary)"} -- Hungary links.IDN = Country:newWithSimpleLinks{[{"N", "National", "National Highway"}] = "Indonesian National Route %s"} -- Indonesia links.ITA = Country:newWithSimpleLinks{["A"] = "Autostrada A%s (Italy)"} -- Italy links.JOR = Link:new{formatStr = "Highway %s (Jordan)"} -- Jordan links.JPN = Country:newWithSimpleLinks{[{"National", "Route"}] = "Japan National Route %s"} -- Japan links.KOR = Country:newWithSimpleLinks{[{"National", "NR"}] = "South Korea National Route %s"} -- South Korea links.LKA = Country:newWithSimpleLinks{["E"] = "E%s Expressway (Sri Lanka)", ["A"] = "A%s Highway (Sri Lanka)", ["B"] = "B%s Highway (Sri Lanka)"} -- Sri Lanka links.LVA = Country:newWithSimpleLinks{["A"] = "A%s road (Latvia)"} -- Latvia links.NOR = Country:newWithSimpleLinks{[{"County", "Fylkesvei", "fylkesvei", "Fv", "fv"}] = "Norwegian County Road %s", [{"National", "Riksvei", "riksvei", "Rv", "rv"}] = "Norwegian National Road %s"} -- Norway links.NZL = Country:newWithSimpleLinks{["SH"] = "New Zealand State Highway %s"} -- New Zealand links.POL = Country:newWithSimpleLinks{["A"] = "A%s autostrada (Poland)", ["S"] = "Expressway S%s (Poland)"} -- Poland links.ROU = Country:newWithSimpleLinks{["A"] = "A%s motorway (Romania)", ["DN"] = "DN%s"} -- Romania links.RUS = Country:newWithSimpleLinks{["M"] = "M%s highway (Russia)"} -- Russia links.SVK = Country:newWithSimpleLinks{["D"] = "Motorway D%s (Slovakia)", ["R"] = "R%s expressway (Slovakia)"} -- Slovakia links.SVN = Country:newWithSimpleLinks{["A"] = "A%s motorway (Slovenia)", ["H"] = "H%s expressway (Slovenia)"} -- Slovenia links.TUR = Country:newWithSimpleLinks{[{"otoyol", "O"}] = "Otoyol %s", [{"state", "D"}] = "State road D%s (Turkey)"} -- Turkey links.TWN = Country:newWithSimpleLinks{["NH"] = "National Highway %s (Taiwan)", ["PH"] = "Provincial Highway %s (Taiwan)"} -- Taiwan links.UKR = Country:newWithSimpleLinks{["M"] = "M%s highway (Ukraine)", ["H"] = "Highway H%s (Ukraine)"} -- Ukraine do -- Uruguay local type = Link:new{formatStr = "Route %s (Uruguay)", exceptions={["IB"] = "Ruta Interbalnearia"}} links.URY = Country:new{["route"] = type, ["Route"] = type} end -- Uruguay links.ZAF = Country:newWithSimpleLinks{["N"] = "N%s road (South Africa)", ["R"] = "R%s road (South Africa)"} -- South Africa end

p.links = links

function p._link(args) return links:link(args) end

function p.link(frame) local pframe = frame:getParent local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template local function emptyParam(param) local empty = {[''] = true, ['¬'] = true} if empty[param] then return nil else return param end end local country = args.country or config.country local type = args.type or config.type local state = args.state or config.state state = emptyParam(state) local province = args.province or config.province province = emptyParam(province) local route = args.route or config.route local county = args.county or config.county county = emptyParam(county) local dab = args.dab or config.dab dab = emptyParam(dab) return p._link{country=country, type=type, state=state, province=province, route=route, county=county, dab=dab} end

return p