Module:Routelist row: Difference between revisions

Content deleted Content added
Updating text to match current version of WP:USRD/STDS/L
Adding circa capability
Line 6:
--[[ The following tables include the following entries:
row: The start of the row, for this particular type (color)
established: The string to be output in the "Formed" column. For future routes, "proposed" is displayed here. Otherwise, display the year passed in the established parameter.
removed: The string to be output in the "Removed" column. In the case of routeStates.former, the year that the route was decommissioned is output instead.
]]--
Line 63 ⟶ 64:
end
 
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 date == '' then return false end -- If the date is an empty string, stop and go back to whence it came.
Line 75 ⟶ 76:
local spanParams = {style = "display:none; speak:none"} -- These CSS properties hide the sort key from normal view.
local dtsSpan = mw.text.tag({name='span', contents=dtsStr, params=spanParams}) -- This generates the HTML code necessary for the hidden sort key.
if circa == 'yes' then -- If the date is tagged as circa,
return dtsSpan .. year -- Return the hidden sort key concatenated with the year for this date
return dtsSpan .. "<abbr title=\"circa\">c.</abbr><span style=\"white-space:nowrap;\">&thinsp;" .. year .. "</span>" -- Add the circa abbreviation to the display. Derived from {{circa}}
else -- Otherwise,
return dtsSpan .. year -- Return the hidden sort key concatenated with the year for this date.
end
end
 
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
 
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
 
Line 100 ⟶ 115:
local dates = {["established"] = established, ["decommissioned"] = decommissioned} -- This table encapsulates the given dates into one value...
local routeState = getRouteState(dates) -- which is passed to getRouteState, which returns one of the entries in routeStates,
 
return routeState.row -- whose row attribute is returned
end
Line 120 ⟶ 135:
return '|' .. terminus_a .. '||' .. terminus_b -- Fill in the termini columns
end
end
 
function removed(routeState, decommissioned)
-- This function returns the proper value for the removed column.
return routeState.removed or dtsYear(decommissioned) -- Returns the removed attribute of the provided routeState table or, if empty, the dtsYear-formatted decommissioned date.
end
 
function formed(routeState, established)
-- This function returns the proper value for the formed column.
return routeState.established or dtsYear(established) or "—" -- Returns 'proposed' if the route is proposed, the dtsYear-formatted established date if one was provided, or an em-dash.
end
 
Line 139 ⟶ 144:
-- Import parameters from template
local established = args[".established"] or args["circa"] or '' -- Date established
local decommissioned = args[".decommissioned"] or '' -- Date decommissioned
local dates = {["established"] = established, ["decommissioned"] = decommissioned} -- This table encapsulates the given dates into one value...
local routeState = getRouteState(dates) -- which is passed to getRouteState, which returns one of the entries in routeStates,
local output = "|align=center|" .. formed(routeState, established, args.circa_established) .. "||align=center|" .. removed(routeState, decommissioned, args.circa_decommissioned) -- which is passed to the removed function. This line generates the Wikitext for this part of the row.
return output
end