Module:Infobox road/route/sandbox
Appearance
![]() | This is the module sandbox page for Module:Infobox road/route (diff). |
This module pulls data from road data strings, such as Module:Road data/strings/USA, and passes it through three functions that draw the necessary route marker images and displays the route name in {{Infobox road}}
.
Output examples
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
local p = {}
local SUFFIX = ""
-- Change to main module upon deployment
local parserModuleName = "Module:Road data/parser" .. SUFFIX
local concat = table.concat
local insert = table.insert
local format = mw.ustring.format
local roadDataModule = require("Module:Road data" .. SUFFIX)
-- Links/abbreviations
local function routeText(route, jctname, frame)
local link
local type = route.type
if not type or type == '' then
link = route.route
else
link = roadDataModule.link(route)
end
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
end
end
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 = {'denom', 'county', 'township', 'dab', 'nolink', 'noshield', 'to', 'dir', 'name'}
local routes = {}
local routeCount = 1
return routes
end
local function addErrorMsg(catCode, msg, errorMsg)
errorMsg.code = errorMsg.code or catCode
insert(errorMsg, format('<span style="display: none;">Module:Infobox road/route/sandbox %s</span>', msg))
end
function p._routeInfo(args, frame)
local routes = parseArgs(args)
local shields = {}
local links = {}
local allMissingShields = {}
local typeErr = false
frame = frame or mw.getCurrentFrame()
for num,route in ipairs(routes) do
if not (args.noshield or route.noshield) then
local shield, missingShields = roadDataModule.shield(route)
insert(shields, shield)
if missingShields[1] then
insert(allMissingShields, concat(missingShields, ' / '))
end
end
insert(links, routeText(route, args.jctname, frame))
typeErr = typeErr or route.typeerror or false
end
local graphics = concat(shields) .. ' '
local linkText = concat(links)
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 #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('[[Category:Jct template errors|%s %s]]', errorMsg.code, page))
errorMsg = concat(errorMsg)
else
errorMsg = ''
end
return graphics .. linkText .. errorMsg
end
function p.routeInfo(frame)
-- Import module function to work with passed arguments
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame, {removeBlanks = false})
return p._routeInfo(args, frame)
end
return p