پودمان: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("[[Category:Infobox road transclusion errors|& %s]]", 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%route% (Bangladesh)", ["R"] = "R%route% (Bangladesh)", ["Z"] = "Z%route% (Bangladesh)"} -- Bangladesh
links.CHE = Country:newWithSimpleLinks{["A"] = "A%route% motorway (Switzerland)"} -- Switzerland
links.CHL = Country:newWithSimpleLinks{["CH"] = "Chile Route %route%"} -- Chile
links.CYP = Country:newWithSimpleLinks{["A"] = "A%route% motorway (Cyprus)", ["B"] = "B%route% road (Cyprus)"} -- Cyprus
links.CZE = Country:newWithSimpleLinks{["D"] = "D%route% motorway (Czech Republic)", ["R"] = "R%route% expressway (Czech Republic)"} -- Czech Republic
links.DEU = Country:newWithSimpleLinks{["A"] = "Bundesautobahn %route%", ["B"] = "Bundesstraße %route%"} -- Germany
links.ESP = Country:newWithSimpleLinks{["A"] = "Autovía A-%route%", ["E"] = "European route E%route%", ["M"] = "Autopista M-%route%", ["R"] = "R-%route% motorway (Spain)"} -- Spain
links.EUR = Country:newWithSimpleLinks{["E"] = "European route E%route%"} -- Europe
links.GEO = Country:newWithSimpleLinks{["A"] = "S%route% highway (Georgia)", ["B"] = "Sh%route% road (Georgia)"} -- Georgia
links.GRC = Country:newWithSimpleLinks{["A"] = "Motorway %route% (Greece)", ["EO"] = "Greek National Road %route%"} -- Greece
links.HKG = Country:newWithSimpleLinks{[{"Route", "route"}] = "Route %route% (Hong Kong)"} -- Hong Kong
links.HRV = Country:newWithSimpleLinks{["A"] = "A%route% (Croatia)", ["D"] = "D%route% (Croatia)"} -- Croatia
links.HUN = Country:newWithSimpleLinks{["M"] = "M%route% motorway (Hungary)"} -- Hungary
links.IDN = Country:newWithSimpleLinks{[{"N", "National", "National Highway"}] = "Indonesian National Route %route%"} -- Indonesia
links.ITA = Country:newWithSimpleLinks{["A"] = "Autostrada A%route% (Italy)"} -- Italy
links.JOR = Link:new{formatStr = "Highway %route% (Jordan)"} -- Jordan
links.JPN = Country:newWithSimpleLinks{[{"National", "Route"}] = "Japan National Route %route%"} -- Japan
links.KOR = Country:newWithSimpleLinks{[{"National", "NR"}] = "South Korea National Route %route%"} -- South Korea
links.LKA = Country:newWithSimpleLinks{["E"] = "E%route% Expressway (Sri Lanka)", ["A"] = "A%route% Highway (Sri Lanka)", ["B"] = "B%route% Highway (Sri Lanka)"} -- Sri Lanka
links.LVA = Country:newWithSimpleLinks{["A"] = "A%route% road (Latvia)"} -- Latvia
links.NOR = Country:newWithSimpleLinks{[{"County", "Fylkesvei", "fylkesvei", "Fv", "fv"}] = "Norwegian County Road %route%",
[{"National", "Riksvei", "riksvei", "Rv", "rv"}] = "Norwegian National Road %route%"} -- Norway
links.NZL = Country:newWithSimpleLinks{["SH"] = "New Zealand State Highway %route%"} -- New Zealand
links.POL = Country:newWithSimpleLinks{["A"] = "A%route% autostrada (Poland)", ["S"] = "Expressway S%route% (Poland)"} -- Poland
links.ROU = Country:newWithSimpleLinks{["A"] = "A%route% motorway (Romania)", ["DN"] = "DN%route%"} -- Romania
links.RUS = Country:newWithSimpleLinks{["M"] = "M%route% highway (Russia)"} -- Russia
links.SVK = Country:newWithSimpleLinks{["D"] = "Motorway D%route% (Slovakia)", ["R"] = "R%route% expressway (Slovakia)"} -- Slovakia
links.SVN = Country:newWithSimpleLinks{["A"] = "A%route% motorway (Slovenia)", ["H"] = "H%route% expressway (Slovenia)"} -- Slovenia
links.TUR = Country:newWithSimpleLinks{[{"otoyol", "O"}] = "Otoyol %route%", [{"state", "D"}] = "State road D%route% (Turkey)"} -- Turkey
links.TWN = Country:newWithSimpleLinks{["NH"] = "National Highway %route% (Taiwan)", ["PH"] = "Provincial Highway %route% (Taiwan)"} -- Taiwan
links.UKR = Country:newWithSimpleLinks{["M"] = "M%route% highway (Ukraine)", ["H"] = "Highway H%route% (Ukraine)"} -- Ukraine
do -- Uruguay
local type = Link:new{formatStr = "Route %route% (Uruguay)", exceptions={["IB"] = "Ruta Interbalnearia"}}
links.URY = Country:new{["route"] = type, ["Route"] = type}
end -- Uruguay
links.ZAF = Country:newWithSimpleLinks{["N"] = "N%route% road (South Africa)", ["R"] = "R%route% 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