local p = -- Change to "" upon deployment.local moduleSuffix = ""
local parserModuleName = "Module:Road data/parser" .. moduleSuffixlocal cityModuleName = "Module:Jct/city" .. moduleSuffix
local concat = table.concatlocal insert = table.insertlocal format = mw.ustring.formatlocal trim = mw.text.trim
local parserModule = require(parserModuleName)local parser = parserModule.parserlocal util = require("Module:Road data/util")local displayModule = require("Module:Sandbox/BrandonXLF/4")
-- Shieldslocal defaultShieldSize = 24
-- Links/abbreviationslocal function routeText(route, jctname, frame) local link local type = route.type if not type or type
local dir = route.dir and ' ' .. string.lower(route.dir) or local routeText = link .. dir
local name = route.name if name and name ~= then local mainText = jctname and name or routeText local parenText = jctname and routeText or name return format('%s (%s)', mainText, parenText) else return routeText endend
local function extra(args) local extraTypes = mw.loadData('Module:Road data/extra') local extraIcon = extraTypes[string.lower(args.extra or '')] if not extraIcon then return end local size = defaultShieldSize .. 'px' local countryIcon = extraIcon[args.country] or extraIcon.default if type(countryIcon)
local function parseArgs(args) local state = args.state or args.province or args.state = state local country if args.country and args.country ~= then country = string.upper(args.country) else local countryModule = mw.loadData("Module:Road data/countrymask") country = countryModule[state] or 'UNK' end args.country = country
local params = local routes = local routeCount = 1 local seenTo = false while true do local routeType = args[routeCount * 2 - 1] if not routeType then break end local route = for _,v in pairs(params) do route[v] = args[v .. routeCount] end if args.nolink then route.nolink = args.nolink end route.country = country route.state = state
-- Set the first .to to true. -- Set all following .to to . if seenTo then if route.to then -- Report duplicate to flag. route.toerror = true end route.to = elseif route.to then route.to = true seenTo = true end
insert(routes, route) routeCount = routeCount + 1 end return routesend
local function prefix(to, num) if to and to ~= then return num
1 and or ' / 'end
local function addErrorMsg(catCode, msg, errorMsg) errorMsg.code = errorMsg.code or catCode insert(errorMsg, format('
Module:Jct %s', msg))endfunction p._jct(args, frame) local routes = parseArgs(args) local shields = local links = local allMissingShields = local typeErr = false local toErr = false frame = frame or mw.getCurrentFrame for num,route in ipairs(routes) do if not (args.noshield or route.noshield) then local shield, missingShields = displayModule.shield(route, nil, 'jct') insert(shields, shield) if missingShields[1] then insert(allMissingShields, concat(missingShields, ' / ')) end end local prefix = prefix(route.to, num) if prefix ~= then insert(links, prefix) end insert(links, routeText(route, args.jctname, frame)) typeErr = typeErr or route.typeerror or false toErr = toErr or route.toerror or false end local graphics = concat(shields) .. extra(args) .. ' ' local linkText = concat(links) local cities = if args.city1 or args.location1 then local citiesPrefix if args.citiesprefix then citiesPrefix = args.citiesprefix ~= and format(" %s ", args.citiesprefix) or else citiesPrefix = ' ' end local cityModule = require(cityModuleName) cities = citiesPrefix .. cityModule.city(args) end
local errorMsg = -- Errors must be reported by the level of severity, most severe first. if typeErr then -- Report invalid type errors. addErrorMsg("§", 'error: Invalid route type', errorMsg) end if #allMissingShields > 0 then -- Report missing shield error. -- shieldExists would have populated missingShields if shields are missing. addErrorMsg("¶", 'error: Missing route marker graphics: ' .. concat(allMissingShields, ' / '), errorMsg) end if toErr then -- Report invalid to errors. addErrorMsg("&", 'error: Invalid "to" argument', errorMsg) end if args.road then -- Report deprecated "road" warning. addErrorMsg("∆", 'warning: "road" parameter is deprecated', errorMsg) end if args.rdt then -- Report deprecated "rdt" warning. addErrorMsg("£", 'warning: "rdt" parameter is deprecated', errorMsg) end if #errorMsg > 0 then local page = mw.title.getCurrentTitle.prefixedText -- Get transcluding page's title -- Add a category for the first, most severe error. insert(errorMsg, format('', errorMsg.code, page)) errorMsg = concat(errorMsg) else errorMsg = end
return graphics .. linkText .. cities .. errorMsgend
function p.jct(frame) -- Import module function to work with passed arguments local getArgs = require('Module:Arguments').getArgs local args = getArgs(frame,) return p._jct(args, frame)end
function p._roadlink(args, frame) local routes = parseArgs(args) local links = local typeErr = false local toErr = false frame = frame or mw.getCurrentFrame for num,route in ipairs(routes) do local prefix = prefix(route.to, num) if prefix ~= then insert(links, prefix) end insert(links, routeText(route, args.jctname, frame)) typeErr = typeErr or route.typeerror or false toErr = toErr or route.toerror or false end local linkText = concat(links) local cities = if args.city1 or args.location1 then local citiesPrefix if args.citiesprefix then citiesPrefix = args.citiesprefix ~= and format(" %s ", args.citiesprefix) or else citiesPrefix = ' ' end local cityModule = require(cityModuleName) cities = citiesPrefix .. cityModule.city(args) end
local errorMsg = -- Errors must be reported by the level of severity, most severe first. if typeErr then -- Report invalid type errors. addErrorMsg("2", 'error: Invalid route type', errorMsg) end if toErr then -- Report invalid to errors. addErrorMsg("3", 'error: Invalid "to" argument', errorMsg) end if args.road then -- Report deprecated "road" warning. addErrorMsg("W", 'warning: "road" parameter is deprecated', errorMsg) end if #errorMsg > 0 then local page = mw.title.getCurrentTitle.prefixedText -- Get transcluding page's title -- Add a category for the first, most severe error. insert(errorMsg, format('', errorMsg.code, page)) errorMsg = concat(errorMsg) else errorMsg = end
return linkText .. citiesend
function p.roadlink(frame) -- Import module function to work with passed arguments local getArgs = require('Module:Arguments').getArgs local args = getArgs(frame,) return p._roadlink(args, frame)end
return p