Module:Infobox road/link/USA

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 Preprocessors = {}

do local statesData = mw.loadData("Module:U.S. States/data") local mapping = statesData.stateName function Preprocessors.stateName(args) args.stateName = mapping[args.state] end function stateName(state) return mapping[state] end end

local links = Country:new do -- Link definitions --do -- Interstates       local function stateNameArg(args)            local state = args.state            if state then                args.stateNameArg = format(" in %s", stateName(state))            else                args.stateNameArg = ""            end        end        local type = Link:new{formatStr = "Interstate %s%s", formatArgs = {"route", "stateNameArg"}, preprocessors = {stateNameArg}}        links["I"] = type        links["Interstate"] = type        links["I 1957"] = type        links["Future"] = type    end -- Interstates -- do -- Interstates local type = {} function type:link(args) local route = args.route local state = args.state if state then return format("Interstate %s in %s", route, stateName(state)) else return format("Interstate %s", route) end end links["I"] = type links["Interstate"] = type links["I 1957"] = type links["Future"] = type end -- Interstates --do -- U.S. Routes       local function stateNameArg(args)            local state = args.state            if state then                args.stateNameArg = format(" in %s", stateName(state))            else                args.stateNameArg = ""            end        end        local type = Link:new{formatStr = "U.S. Route %s%s", formatArgs = {"route", "stateNameArg"}, preprocessors = {stateNameArg}}        links["US"] = type        links["US 1926"] = type        links["US 1948"] = type        links["US 1950"] = type    end -- U.S. Routes -- do -- U.S. Routes local type = {} function type:link(args) local route = args.route local state = args.state if state then return format("U.S. Route %s in %s", route, stateName(state)) else return format("U.S. Route %s", route) end end links["US"] = type links["US 1926"] = type links["US 1948"] = type links["US 1950"] = type end -- U.S. Routes -- links["NER"] = Link:new{formatStr = "New England Interstate Route %s"} -- New England Interstate Routes do -- New England Interstate Routes local type = {} function type:link(args) return format("New England Interstate Route %s", args.route) end links["NER"] = type end -- New England Interstate Routes end -- Link definitions

p.links = links return p