local p = -- Package to be exportedlocal getArgs = require('Module:Arguments').getArgs -- Import module function to work with passed argumentslocal lang = mw.getContentLanguage -- Retrieve built-in locale for date formattinglocal format = mw.ustring.format -- String formatting functionlocal frame = mw.getCurrentFramelocal roadDataModule = require("Module:Road data/sandbox") -- REMOVE SANDBOX
local routeStates = -- Table with route statuses.----routeStates.current = -- Data for current routesrouteStates.future = -- Data for future routesrouteStates.former = -- Data for former routesrouteStates.formeroverride = -- Data for routes marked as former by overriderouteStates.unknown = -- Data for route with unknown status
local function getRouteState(established, decommissioned) --This function is passed the dates given for the established and decommissioned fields to the template. It then returns the entry in the routeStates table corresponding to the status of the route. -- if decommissioned
'proposed' then -- If the "established date" is the string 'proposed', then it must be a future route. return routeStates.future else -- If none of the first three conditions are true, then it must be a current route. return routeStates.current endend
local function dtsYearCore(date, circa) -- A limited replacement for . This is passed a date and derives a sort key from it. It returns a string with the hidden sort key, along with the year of the original date. if not date then return false end -- If the date is an empty string, stop and go back to whence it came. local year = lang:formatDate('Y', date) -- This invocation of lang:formatDate returns just the year. if year
'yes' then -- If the date is tagged as circa, return dtsSpan .. "c.
 " .. year .. "" -- Add the circa abbreviation to the display. Derived from else -- Otherwise, return dtsSpan .. year -- Return the hidden sort key concatenated with the year for this date. endendlocal function dtsYear(date, circa) local success, result = pcall(dtsYearCore, date, circa) if success then return result else return string.format('%s
Error: Invalid date "%s".', circa and 'c. ' or , date) endendlocal function removed(routeState, decommissioned, circa) -- This function returns the proper value for the removed column. return routeState.removed or dtsYear(decommissioned, circa) -- Returns the removed attribute of the provided routeState table or, if empty, the dtsYear-formatted decommissioned date.end
local function formed(routeState, established, circa) -- This function returns the proper value for the formed column. return routeState.established or dtsYear(established, circa) or "—" -- Returns 'proposed' if the route is proposed, the dtsYear-formatted established date if one was provided, or an em-dash.end
local function sortkey(args) -- This function return the sort key for the route (not to be confused with the previous function, which generates a sort key for the established and decommissioned dates.) local key = args.sortkey local type = args.type local route = args.route or if key then -- If a sort key already exists: return key -- Simply return it. else -- Otherwise: local routeKey local routeNum = tonumber(route) if routeNum then routeKey = string.format('%04d', route) -- This invocation is equivalent to the template. It zero-pads the given route number up to 4 digits. else local num, suffix = string.match(route, "(%d*)(.+)") routeKey = (tonumber(num) and string.format('%04d', num) or ) .. suffix end return type .. routeKey -- Return the sort key for this route, composed of the type and zero-padded route number. endend
local function termini(args) -- This function determines if this is a beltway or not, and displays the termini columns appropriately. local beltway = args["beltway"] -- Text in this parameter will span both termini columns. local terminus_a = args["terminus_a"] or '—' -- Southern or western terminus local terminus_b = args["terminus_b"] or '—' -- Northern or eastern terminus if beltway then return "|colspan=2 align=center|" .. beltway -- This text will, again, span both columns. else return '|' .. terminus_a .. '||' .. terminus_b -- Fill in the termini columns endend
local function dates(established, decommissioned, routeState, args) -- This function displays the date columns. if args.gazette
--- Return output for the length columns for a given route, with the appropriate conversions.local function length(args) local km = args["length_km"] or -- Length in kilometers local mi = args["length_mi"] or -- Length in miles local ref = args["length_ref" ] or
if mi
then return format("|align=right|—||align=right|—") elseif mi ~= '0' and km
local function localname(args) -- This function generates a "Local names" cell if necessary local enabled = args[1] or local localName = args["local"] or if mw.text.trim(enabled)
local function notes(notes) -- This function generates a "Notes" cell if necessary. if notes
local function gap(args) local text = args.text or "Number not designated" if notes then return '|align=center colspan=7|' .. text --display notes in cell else return '|align=center colspan=6|' .. text --display notes in cell endend
local function route(args) -- This function displays the shield and link. local format = mw.ustring.format local parserModule = require "Module:Road data/parser" local parser = parserModule.parser local noshield = args.noshield
local shield if not noshield then shield = roadDataModule.shield(args, 'list') else shield = end local link = roadDataModule.link(args) local sortkey = sortkey(args) local sortedLink = format("
%s", sortkey, link) local route = shield .. ' ' .. sortedLink return '!scope="row" class="nowrap"|' .. routeendfunction p.row(frame) local args = getArgs(frame) -- Gather passed arguments into easy-to-use table local established = args.established local decommissioned = args.decommissioned local routeState = getRouteState(established, decommissioned) local anchor = args.anchor or sortkey(args) local rowdef = routeState.row .. string.format(' id="%s"', anchor) local route = route(args) local length = length(args) local termini = termini(args) local localname = localname(args) local dates = dates(established, decommissioned, routeState, args) local notesArg = args.notes local notes = notes(notesArg) local row = return table.concat(row, '\n')end
function p.gap(frame) local args = getArgs(frame) -- Gather passed arguments into easy-to-use table
local routeState = getRouteState(established, decommissioned) local anchor = args.anchor or sortkey(args) local rowdef = routeState.row .. string.format(' id="%s"', anchor) local route = route(args) local gap = gap(args) local row = return table.concat(row, '\n')end
return p