Content deleted Content added
Display an em-dash instead of 0 in distance columns when neither length is passed. |
drop nowrap - was causing horizontal scrolling on List of Ontario provincial highways for 407 |
||
(32 intermediate revisions by 6 users not shown) | |||
Line 2:
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
local format = mw.ustring.format -- String formatting function
local frame = mw.getCurrentFrame()
local routeStates = { } -- Table with route statuses.
Line 32 ⟶ 34:
end
function
-- 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.
Line 78 ⟶ 45:
local dtsStr = string.format("%05d-%02d-%02d", year, month, day) -- Create and store the formatted hidden sort key. The year must be five digits, per convention.
local spanParams = {style = "display:none; speak:none"} -- These CSS properties hide the sort key from normal view.
local dtsSpan = mw.text.tag({name='span',
if circa == 'yes' then -- If the date is tagged as circa,
return dtsSpan .. "<abbr title=\"circa\">c.</abbr><span style=\"white-space:nowrap;\"> " .. 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 dtsYear(date, circa)
local success, result = pcall(dtsYearCore, date, circa)
if success then
return result
else
return string.format('%s<span class="error">Error: Invalid date "%s".</span>', circa and '<abbr title="circa">c.</abbr> ' or '', date)
end
end
Line 109 ⟶ 85:
routeKey = string.format('%04d', route) -- This invocation is equivalent to the {{0000expr}} 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.
Line 131 ⟶ 107:
function dates(established, decommissioned, routeState, args)
-- This function displays the date columns.
if args.gazette == 'yes' then
local established = args.established or "—"
local established_ref = args.established_ref or ''
return "|align=center|" .. established .. established_ref
else
local established_ref = args.established_ref or '' -- Reference for date established
local decommissioned_ref = args.decommissioned_ref or '' -- Reference for date decommissioned
return "|align=center|" .. formed(routeState, established, args.circa_established) ..
established_ref .. "||align=center|" .. removed(routeState, decommissioned, args.circa_decommissioned) ..
decommissioned_ref
end
end
--- Return output for the length columns for a given route, with the appropriate conversions.
local function length(args)
local
local ref = args["length_ref" ] or ''
if mi == '' and km == '' then
return format("|align=right|—||align=right|—")
elseif mi ~= '0' and km == '' then
return format("|align=right|") .. mi .. ref .. format("||align=right|") .. frame:expandTemplate{ title = 'convert', args = { mi, "mi", "km", disp = "output number only"}}
else
return format("|align=right|") .. km .. ref .. format("||align=right|") .. frame:expandTemplate{ title = 'convert', args = { km, "km", "mi", disp = "output number only"}}
end
end
Line 177 ⟶ 157:
else
return '' --create no cell
end
end
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
end
end
Line 232 ⟶ 222:
banner = ''
end
local shield
if not noshield then
local shieldFile, second = parser(args, 'shieldlist') or parser(args, 'shield') or ''
if
shield = ''
elseif type(shieldFile) == 'table' then
shieldFile, second = shieldFile[1], shieldFile[2]
end
if second and type(second) == 'string' then
local shield1 = format("[[File:%s|x25px|alt=|link=]]", shieldFile)
local shield2 = format("[[File:%s|x25px|alt=|link=]]", second)
shield = shield1 .. shield2
elseif shield == '' then
shield = ''
else
shield = shieldFile and format("[[File:%s|x25px|alt=|link=]]", shieldFile) or ''
Line 257 ⟶ 254:
if not link then error("Type not in database: " .. args.type) end
local sortkey = sortkey(args)
local sortedLink = format("<span
local route = banner .. shield .. ' ' .. sortedLink
return '
end
Line 279 ⟶ 276:
local row = {rowdef, route, length, termini, localname, dates, notes}
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 = {rowdef, route, gap}
return table.concat(row, '\n')
end
|