Module:Road data/browse
Appearance
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 18,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
This module is used by Template:Infobox road (via Module:Infobox road), but can be used outside of the infobox. Also see Module:Road data/browsetable which can serve as a container for the output produced by the module.
This module powers many of the templates in Category:Browse templates. The unified documentation Template:Browse template documentation exists for those templates.
local p = {}
local getArgs = require('Module:Arguments').getArgs -- Import module function to work with passed arguments
local parserModule = require "Module:Road data/parser"
local parser = parserModule.parser
local function size(args)
local country = args.country
local state = args.state or args.province
local type = args.type
if country == 'MEX' then
return "20x30"
elseif country == 'CAN' then
if state == 'AB' or state == 'QC' or state == 'SK' then
return "20x30"
elseif state == 'NS' then
if (type == 'NS' or type == 'Hwy') then
return "18"
else
return "x20"
end
elseif state == 'ON' then
if type == 'ON' or type == 'Hwy' or type == 'Fwy' then
return "20x30"
elseif type == 'CR' or type == 'RR' then
return "30x32"
end
end
return "25x20"
elseif country == 'USA' then
if state == 'NY' and (type == 'NY 1927' or type == 'NY 1948') then
return '20'
end
end
return 'x20'
end
local function shield(args)
local size = size(args)
local shield = parser(args, 'shield')
if not shield or shield == '' then return '' end
return string.format("[[File:%s|%spx|link=|alt=]]", shield, size)
end
local function link(args)
local abbr = parser(args, 'abbr')
local link = parser(args, 'link')
if not link or link == '' then
return mw.ustring.format("<span class=\"nowrap\">%s</span>", abbr)
else
return mw.ustring.format("<span class=\"nowrap\">[[%s|%s]]</span>", link, abbr)
end
end
local function previousRoute(args)
local shieldText = shield(args)
local linkText = link(args)
local cell = mw.html.create('td'):css( {width = "45%", ["vertical-align"] = "middle", padding = "0", ["text-align"] = "left"} )
cell:wikitext("← " .. shieldText .. ' ' .. linkText)
return cell
end
local function nextRoute(args)
local shieldText = shield(args)
local linkText = link(args)
local cell = mw.html.create('td'):css( {width = "45%", ["vertical-align"] = "middle", padding = "0", ["text-align"] = "right"} )
cell:wikitext(linkText .. ' ' .. shieldText .. " →")
return cell
end
function p._browse(args)
local browseRow = mw.html.create('tr')
local country = args.country
local state = args.state or args.province
local county = args.county
local previousData = {country = country, state = state, county = county,
type = args.previous_type, route = args.previous_route,
dab = args.previous_dab}
local nextData = {country = country, state = state, county = county,
type = args.next_type, route = args.next_route,
dab = args.next_dab}
local previousRoute = previousRoute(previousData)
local nextRoute = nextRoute(nextData)
local centerRoute = mw.html.create('td'):css( {["text-align"] = "center", ["white-space"] = "nowrap", width = "10%", ["vertical-align"] = "middle", padding = "0"} )
local route = args.browse_route
if route then
centerRoute:wikitext("'''" .. route .. "'''")
end
browseRow:node(previousRoute):node(centerRoute):node(nextRoute)
return tostring(browseRow)
end
function p.browse(frame)
local args = getArgs(frame)
args.browse_route = args.route
return p._browse(args)
end
return p