local p =
local SANDBOX = falselocal SANDBOX_SUFFIX = SANDBOX and '/sandbox' or
local concat = table.concatlocal insert = table.insertlocal getArgs = require('Module:Arguments').getArgs -- Import module function to work with passed argumentslocal parserModule = require("Module:Road data/parser" .. SANDBOX_SUFFIX)local parser = parserModule.parser
-- Shieldslocal rdt
local function size(args) local country = args.country local state = args.state or args.province or local type = args.type if rdt then return 'x17' elseif state
'Toll' or type
'HEFT' then return '20' elseif type
'NY' then if type
'NY 1948' or (type
"Robert Moses") or (type
'Erie') then return '20' end elseif state
'AB' or type
'2ndHwy' or type
'NS' and type
'TCH' then return '18' elseif state
'ON' or type
'Highway' or type
'KLR' then return '21' else local countyTypes = if countyTypes[type] then return '19' end end elseif state
'QC' or type
'A' or type
'TCH' or type
'SK' then if type
'SK' then return 'x25' end elseif country
'FRA' then return 'x18' elseif country
then return elseif type(shield)
'string' then local size = secondSize or firstSize rendered = rendered .. render(second, size) end return renderedend
-- Links/abbreviationslocal function link(args) local nolink = args.nolink local abbr = parser(args, 'abbr') if nolink then return abbr else local link = parser(args, 'link') if not link or link
local function completeLink(args, num) local actualLink = link(args) if not actualLink then local page = mw.title.getCurrentTitle.prefixedText -- Get transcluding page's title actualLink = string.format("
Invalid type: %s", args.type, page) end local isTo = args.to local prefix if numlocal function namedLink(args, num) local actualLink = link(args) local name = args.name or local isTo = args.to local prefix if num
local function banners(routes) local format = string.format local firstRun = local hasBanner = false for k,v in ipairs(routes) do local banner if v.shield
then local widthCode = parser(v, 'width') or 'square' if type(widthCode)
'square' then insert(secondRun, "") elseif widthCode
'wide' then insert(secondRun, "") elseif widthCode
'SD' then local route = v.route local width = (#route >= 3) and '23' or '20' insert(secondRun, format("", width)) elseif (v.state
'CA') then local route = v.route local widths = local width = widths[widthCode] or widths.default local pixels = (#route >= 3) and width[2] or width[1] insert(secondRun, format("", pixels)) end else local widthCode = parser(v, 'width') or 'square' if widthCode
'expand' then local route = v.route if #route >= 3 then insert(secondRun, format("", bannerFile)) else insert(secondRun, format("", bannerFile)) end elseif widthCode
'SD' then local route = v.route if #route >= 3 then insert(secondRun, format("", bannerFile)) else insert(secondRun, format("", bannerFile)) end elseif widthCode
'US1926' then insert(secondRun, format("", bannerFile)) elseif v.state
'US-Bus' then if #route >= 3 then insert(secondRun, format("", bannerFile)) else insert(secondRun, format("", bannerFile)) end elseif type
'SR-Bus' then if #route >= 3 then insert(secondRun, format("", bannerFile)) else insert(secondRun, format("", bannerFile)) end end end end end return concat(secondRun) .. '
'end
local function extra(args) local extraTypes = local extraIcon = extraTypes[string.lower(args.extra or '')] if not extraIcon then return elseif type(extraIcon)
'table' then return extraIconT[args.state] or extraIconT[args.province] or extraIconT.default else return extraIconT end else return extraIcon endend
local function parseArgs(args) local state = args.state or args.province local country if args.country then country = string.upper(args.country) args.country = country else local countryModule = mw.loadData("Module:Road data/countrymask") country = countryModule[state] or 'UNK' args.country = country end local params = local routeArgs = local routeCount = 1 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 insert(routeArgs, route) routeCount = routeCount + 1 end return routeArgsend
function p._jct(args, frame) rdt = args.rdt local routes = parseArgs(args) local extra = extra(args) local shields = local links = frame = frame or mw.getCurrentFrame for num,route in ipairs(routes) do local routeShield = shield(route, frame) insert(shields, routeShield) route.shield = routeShield if args.jctname then insert(links, namedLink(route, num)) else insert(links, completeLink(route, num)) end end local bannerText = banners(routes) local shieldText = concat(shields) local linkText = concat(links) local graphics = (not(args.noshield) and (bannerText .. shieldText) or ) .. extra .. ' ' local cities = if args.city1 or args.location1 then local cityModule = require("Module:Jct/city" .. SANDBOX_SUFFIX) cities = cityModule.city(args) end local roadStr = local road = args.road if road then if args.toroad then roadStr = ' to ' .. road else roadStr = ' / ' .. road end end local output = graphics .. linkText .. roadStr .. cities return mw.text.trim(output)end
function p.jct(frame) local args = getArgs(frame) return p._jct(args, frame)end
return p