Content deleted Content added
Add decommission override feature |
Sync with sandbox: Sortkey as anchor; unlinking possible; use Module:Arguments; other fixes |
||
Line 1:
local p = { } -- Package to be exported
local getArgs = require('Module:Arguments').getArgs -- Import module function to work with passed arguments
local lang = mw.getContentLanguage() -- Retrieve built-in locale for date formatting
Line 20 ⟶ 21:
if decommissioned == 'yes' then --If the decommissioned property just says "yes", then mark it as a former route and display default data.
return routeStates.formeroverride
elseif decommissioned
return routeStates.former
elseif not established
return routeStates.unknown
elseif established == 'proposed' then -- If the "established date" is the string 'proposed', then it must be a future route.
Line 39 ⟶ 40:
local km = args["length_km"] -- The kilometer length from the {{routelist row}} call.
local mi = args["length_mi"] -- The length in miles as passed to {{routelist row}}.
if
local n = tonumber(mi) -- The first step is to convert the miles (passed as a string from the template) into a number.
local prec = precision(mi) -- Retrieve the precision of the passed mile value (as a string).
Line 50 ⟶ 51:
length.km = km
end
if
local n = tonumber(km) -- Kilometers as a number
local prec = precision(km) -- Precision of the passed length
Line 66 ⟶ 67:
function dtsYear(date, circa)
-- A limited replacement for {{dts}}. 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
local year = lang:formatDate('Y', date) -- This invocation of lang:formatDate returns just the year.
if year == date then -- If the provided date is just the year:
Line 95 ⟶ 96:
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
return key -- Simply return it.
else -- Otherwise:
Line 115 ⟶ 116:
function termini(args)
-- This function determines if this is a beltway or not, and displays the termini columns appropriately.
local beltway = args["beltway"]
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
Line 137 ⟶ 138:
function length(args)
-- This function generate the length columns, with the appropriate conversions.
local miles = args["length_mi"]
local kilometers = args["length_km"]
local lengths = {length_mi = miles, length_km = kilometers} -- This time, we compile the lengths into a table,
local Lengths = getLength(lengths) -- which makes for an easy parameter. This function call will return the lengths in both miles and kilometers,
Line 144 ⟶ 145:
local lengthRef = args["length_ref"] or ''
local first, second
if kilometers
first = Lengths.km
second = Lengths.mi
Line 170 ⟶ 171:
if notes == 'none' then
return '| ' --create empty cell
elseif notes
return '|' .. notes --display notes in cell
else
Line 196 ⟶ 197:
end
local linkTarget = (not args.nolink) and parser(args, 'link')
local abbr = parser(args, 'abbr')
local link
Line 212 ⟶ 213:
function 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
local rowdef = routeState.row .. string.format(' id="%s"', sortkey)
local route = route(args)
local length = length(args)
Line 225:
local localname = localname(args)
local dates = dates(established, decommissioned, routeState, args)
local notesArg = args.notes
local notes = notes(notesArg)
|