Jump to content

Module:Routelist row and Module:Routelist row/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
drop nowrap - was causing horizontal scrolling on List of Ontario provincial highways for 407
 
No edit summary
 
Line 4: Line 4:
local format = mw.ustring.format -- String formatting function
local format = mw.ustring.format -- String formatting function
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
local roadDataModule = require("Module:Road data/sandbox") -- REMOVE SANDBOX


local routeStates = { } -- Table with route statuses.
local routeStates = { } -- Table with route statuses.
Line 17: Line 18:
routeStates.unknown = {row = "|-", removed = "—"} -- Data for route with unknown status
routeStates.unknown = {row = "|-", removed = "—"} -- Data for route with unknown status


function getRouteState(established, decommissioned)
local function getRouteState(established, decommissioned)
--[[ This function is passed the dates given for the established and decommissioned fields to the template.
--[[ 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.
It then returns the entry in the routeStates table corresponding to the status of the route.
Line 34: Line 35:
end
end


function dtsYearCore(date, circa)
local function dtsYearCore(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.
-- 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.
if not date then return false end -- If the date is an empty string, stop and go back to whence it came.
Line 53: Line 54:
end
end


function dtsYear(date, circa)
local function dtsYear(date, circa)
local success, result = pcall(dtsYearCore, date, circa)
local success, result = pcall(dtsYearCore, date, circa)
if success then
if success then
Line 62: Line 63:
end
end


function removed(routeState, decommissioned, circa)
local function removed(routeState, decommissioned, circa)
-- This function returns the proper value for the removed column.
-- 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.
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
end


function formed(routeState, established, circa)
local function formed(routeState, established, circa)
-- This function returns the proper value for the formed column.
-- 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.
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
end


function sortkey(args)
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.)
-- 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 key = args.sortkey
Line 92: Line 93:
end
end


function termini(args)
local function termini(args)
-- This function determines if this is a beltway or not, and displays the termini columns appropriately.
-- 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 beltway = args["beltway"] -- Text in this parameter will span both termini columns.
Line 105: Line 106:
end
end


function dates(established, decommissioned, routeState, args)
local function dates(established, decommissioned, routeState, args)
-- This function displays the date columns.
-- This function displays the date columns.
Line 138: Line 139:
end
end


function localname(args)
local function localname(args)
-- This function generates a "Local names" cell if necessary
-- This function generates a "Local names" cell if necessary
local enabled = args[1] or ''
local enabled = args[1] or ''
Line 149: Line 150:
end
end


function notes(notes)
local function notes(notes)
-- This function generates a "Notes" cell if necessary.
-- This function generates a "Notes" cell if necessary.
if notes == 'none' then
if notes == 'none' then
Line 160: Line 161:
end
end


function gap(args)
local function gap(args)
local text = args.text or "''Number not designated''"
local text = args.text or "''Number not designated''"
Line 170: Line 171:
end
end


function route(args)
local function route(args)
-- This function displays the shield and link.
-- This function displays the shield and link.
local format = mw.ustring.format
local format = mw.ustring.format
Line 177: Line 178:
local noshield = args.noshield
local noshield = args.noshield
local bannerFile = parser(args, 'banner')
local banner
if not noshield and bannerFile and bannerFile ~= '' then
local widthCode = parser(args, 'width') or 'square'
if widthCode == 'square' then
banner = format("[[File:%s|25px|link=|alt=]]", bannerFile)
elseif widthCode == 'expand' then
local route = args.route
if #route >= 3 then
banner = format("[[File:No image.svg|3px|link=|alt=]][[File:%s|25px|link=|alt=]][[File:No image.svg|3px|link=|alt=]]", bannerFile)
else
banner = format("[[File:%s|25px|link=|alt=]]", bannerFile)
end
elseif widthCode == 'wide' then
banner = format("[[File:No image.svg|3px|link=|alt=]][[File:%s|25px|link=|alt=]][[File:No image.svg|3px|link=|alt=]]", bannerFile)
elseif widthCode == 'MOSupp' then
local route = args.route
if #route >= 2 then
banner = format("[[File:No image.svg|3px|link=|alt=]][[File:%s|25px|link=|alt=]][[File:No image.svg|3px|link=|alt=]]", bannerFile)
else
banner = format("[[File:%s|25px|link=|alt=]]", bannerFile)
end
elseif widthCode == 'US1926' then
banner = format("[[File:%s|25px|link=|alt=]][[File:No image.svg|1px|link=|alt=]]", bannerFile)
elseif args.state == 'CA' then
local route = args.route
local type = args.type
if type == 'US-Bus' then
if #route >= 3 then
banner = format("[[File:No image.svg|2px|link=|alt=]][[File:%s|25px|link=|alt=]][[File:No image.svg|2px|link=|alt=]]", bannerFile)
else
banner = format("[[File:%s|25px|link=|alt=]]", bannerFile)
end
elseif type == 'CA-Bus' or type == 'SR-Bus' then
if #route >= 3 then
banner = format("[[File:No image.svg|1px|link=|alt=]][[File:%s|25px|link=|alt=]][[File:No image.svg|2px|link=|alt=]]", bannerFile)
else
banner = format("[[File:%s|24px|link=|alt=]]", bannerFile)
end
end
end
banner = banner .. '<br>'
else
banner = ''
end


local shield
local shield
if not noshield then
if not noshield then
shield = roadDataModule.shield(args, 'list')
local shieldFile, second = parser(args, 'shieldlist') or parser(args, 'shield') or ''
if shieldFile == nil or shieldFile == '' then
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 ''
end
else
else
shield = ''
shield = ''
end
end
local linkTarget = (not args.nolink) and parser(args, 'link')
local link = roadDataModule.link(args)
local abbr = parser(args, 'abbr')
local link
if linkTarget then
link = format("[[%s|%s]]", linkTarget, abbr)
else
link = abbr
end
if not link then error("Type not in database: " .. args.type) end
local sortkey = sortkey(args)
local sortkey = sortkey(args)
local sortedLink = format("<span data-sort-value=\"%s&#32;!\">%s</span>", sortkey, link)
local sortedLink = format("<span data-sort-value=\"%s&#32;!\">%s</span>", sortkey, link)
local route = banner .. shield .. ' ' .. sortedLink
local route = shield .. ' ' .. sortedLink
return '|' .. route
return '!scope="row" class="nowrap"|' .. route
end
end