local p = {}local getArgs = require('Module:Arguments').getArgslocal yesno = require('Module:Yesno')local data = mw.loadData('Module:Jcon/data')-- Generate the wikitext for the shieldlocal function shieldWikitext(route, roadInfo, args)local size = args.size or '20px' -- Image sizelocal fileNamelocal titleObjif  roadInfo.prefix == 'Ontario' and (tonumber(({route:gsub('%D', '')})[1]) or 0) >= 500 then -- Exception for secondary and tertiary highwaysfileName = 'Ontario Highway ' .. route .. '.svg'elseif roadInfo.prefix == 'Ontario' and route:gsub('%s+', ''):upper() == '407ETR' then -- Exception for 407 ETRfileName = yesno(args.shield) and '407 Express Toll Route Traffic Sign.svg' or 'Highway407crest.svg'elseif roadInfo.shield and yesno(args.shield) then -- Shield format (used as reassurance marker)fileName = roadInfo.shield:format(route)elseif roadInfo.guide then  -- Guide format (used on guide signs)fileName = roadInfo.guide:format(route)elsereturn '' -- Return nothing if no file format was foundendtitleObj = mw.title.new('File:' .. fileName)if not titleObj or not titleObj.file.exists thenreturn '' -- Return nothing if no existing file was foundendreturn '[[File:' .. fileName .. '|alt=|link=|' .. size .. ']]' -- Return the file wikitextend-- Generate the text part of the outputlocal function getText(route, roadInfo, args)local link = ''local display = ''if roadInfo.prefix == 'Ontario' and route:gsub('%s+', ''):upper() == '407ETR' then -- Exception for the 407 ETRlink = 'Ontario Highway 407'display = '407 ETR'elseif roadInfo.prefix == 'Ontario' and route:upper() == 'QEW' then -- Exception for the QEWlink = 'Queen Elizabeth Way'display = 'Queen Elizabeth Way'elseif roadInfo.prefix == 'Toronto' and route:upper() == 'DVP' then -- Exception for the DVPlink = 'Don Valley Parkway'display = 'Don Valley Parkway'elseif roadInfo.prefix == 'Toronto' and route == 'Gardiner' then -- Exception for the Gardiner Expresswaylink = 'Gardiner Expressway'display = 'Gardiner Expressway'elselink = roadInfo.prefix .. ' ' .. roadInfo.type .. ' ' .. routedisplay = roadInfo.type .. ' ' .. routeendlocal titleObj = mw.title.new(link)if (((titleObj and titleObj.exists) or yesno(args.showred)) and not yesno(args.nolink)) then -- Check if the link show be shownreturn '[[' .. link .. '|' .. display .. ']]' -- Return the linkelsereturn display -- Fallback to returning the display textendend-- Gets the wikitext for a placelocal function getPlace(place, args)local placeArticle = place .. ', Ontario'local titleObj = mw.title.new(placeArticle)if (titleObj and titleObj.exists) or yesno(args.showred) thenreturn '[[' .. placeArticle .. '|' .. place .. ']]'elsereturn placeendend-- Entry functionfunction p.jcon(frame)local args = getArgs(frame)local roadType = (args[1] or ''):lower() -- Get the route type (region)local route = args[2] or '' -- Get the route numberlocal placeTypes = { -- Place types to remove from lowercase road type'municipality','municipal','city','township','district','county','counties','united counties','region','regional','regional municipality','road'}for index, placeType in ipairs(placeTypes) doroadType = roadType -- Remove the place types from the road type:gsub('^' .. placeType .. ' of ', ''):gsub(' ' .. placeType .. '$', ''):gsub(' ' .. placeType .. ' road$', '')endroadType = data.aliases[roadType] or roadType -- Transform alias into proper nameif data.signs[roadType] or data.signs[route:lower()] thenreturn data.signs[roadType] or data.signs[route:lower()] -- Return signs symbols like airport and hospitalendlocal roadInfo = data.types[roadType] -- Get road type info from the data moduleif not roadInfo or not route thenreturn '​' -- Return ZWSP if road type is not supported or the route is not specifiedendlocal output = ''local shield = ''if yesno(args.ot) then -- Set correct arguments if output should be only textargs.nosh = 'yes'args.nolink = 'yes'end-- Define the shieldif not yesno(args.nosh) then -- If allowed to add shieldshield = shieldWikitext(route, roadInfo, args) -- Return the shield of the main roadif args.con thenif shield ~= '' then shield = shield .. ' ' end -- Add a NBSP if there's already a shieldshield = shield .. shieldWikitext(args.con, roadInfo, args) -- Add the shield for the first concurrencyendif args.con2 thenif shield ~= '' then shield = shield .. ' ' end -- Add a NBSP if there's already a shieldshield = shield .. shieldWikitext(args.con2, roadInfo, args) -- Add the shield for the second concurrencyendif yesno(args.tch) thenif shield ~= '' then shield = shield .. ' ' end -- Add a NBSP if there's already a shieldshield = shield .. '[[File:TCH-blank.svg|x20px]]' -- Add the TCH shieldendendif not yesno(args['pic aft']) thenoutput = shield -- Add the shield if it goes firstend-- Define the textif not yesno(args.notext) then -- If allowed to show textif output ~= '' then output = output .. ' ' end -- Add a NBSP after the shield if it existsoutput = output .. getText(route, roadInfo, args) -- Add text of the main routeif args.con thenoutput = output .. ' / ' .. getText(args.con, roadInfo, args) -- Add text of the first concurrencyendif args.con2 thenoutput = output .. ' / ' .. getText(args.con2, roadInfo, args) -- Add text of the second concurrencyendif yesno(args.tch) thenoutput = output .. ' / [[Trans-Canada Highway|TCH]]' -- Add the TCH textendendif args.dir thenoutput = output .. ' ' .. args.dir -- Add main route directionendif args.condir thenoutput = output .. '/' .. args.condir -- Add first concurrency directionendif args.condir2 thenoutput = output .. '/' .. args.condir2 -- Add second concurrency directionendif args[3] thenoutput = output .. ' (' .. args[3] .. ')'  -- Add the name to the outputendif args.city or args.town thenoutput = output .. ' – ' .. getPlace(args.city or args.town, args) -- Add the first cityif args.city2 or args.town2 thenoutput = output .. ', ' .. getPlace(args.city2 or args.town2, args) -- Add the second cityendendif yesno(args['pic aft']) and shield thenif output ~= '' then output = output .. ' ' end -- Add a space if output already has textoutput = output .. shield -- Add the shield if it goes lastendreturn outputend-- Generates a list of supported regionsfunction p.supported(frame)local reverseAliases = {}local entries = {}local list = mw.html.create('ul') -- Create output list elementfor alias, name in pairs(data.aliases) do -- Reverse the alias table to allow lookup by nameif not reverseAliases[name] thenreverseAliases[name] = {}endtable.insert(reverseAliases[name], alias)endfor name, info in pairs(data.types) do -- Create tables for each regionif reverseAliases[name] thenfor _, alias in ipairs(reverseAliases[name]) doname = name .. ' / ' .. alias -- Add alias to list itemendendlist:tag('li'):wikitext(name, ' ', '(' .. info.prefix .. ' ' .. info.type .. ')')endfor sign, wikitext in pairs(data.signs) doif reverseAliases[sign] thenfor _, alias in ipairs(reverseAliases[sign]) dosign = sign .. ' / ' .. alias -- Add alias to list itemendendlist:tag('li'):wikitext(sign, ' ', wikitext)endreturn tostring(list)endreturn p