Module:Routelist row: Difference between revisions

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 ~= '' then -- If the route is decommissioned, then it must be a former route.
return routeStates.former
elseif not established == '' then -- Without the establishment date, there is not enough information to determine the status of the route.
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 '' ==not km then -- This signifies that a length in kilometers was not passed.
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 '' ==not mi then -- The same as above, but this time converting kilometers to mile if necessary.
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 == '' 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 == 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 or ''
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:
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"] or '' -- 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
if beltway ~= '' then -- The template passes this function an empty string if {{{beltway}}} is not specified by the template user.
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"] or '' -- Length in miles
local kilometers = args["length_km"] or '' -- Length in kilometers
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 ~= '' then
first = Lengths.km
second = Lengths.mi
Line 170 ⟶ 171:
if notes == 'none' then
return '| ' --create empty cell
elseif notes ~= '' then
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 pframe = frame:getParent()
local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
local established = args.established or ''
local decommissioned = args.decommissioned or ''
local routeState = getRouteState(established, decommissioned)
local rowdefsortkey = routeState.rowsortkey(args)
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 or ''
local notes = notes(notesArg)