Module:Infobox road/route

From MOASSpedia
Jump to navigation Jump to search

This module pulls data from road data strings, such as Module:Road data/strings/USA, and passes it through three functions that draw the necessary route marker images and displays the route name in {{Infobox road}}.

Output examples
Description Output Output (sandbox)
Florida Both

State Road 869 marker State Road 869 marker

State Road 869

Script error: No such module "Infobox road/route/sandbox".
No parameters Script error: No such module "Infobox road/route/sandbox".
Only |marker_image=

US 66 (1961 cutout).svg

Script error: No such module "Infobox road/route/sandbox".
Florida |marker_image=none

State Road A1A

Script error: No such module "Infobox road/route/sandbox".
Only |name=

Autoroute 10

Script error: No such module "Infobox road/route/sandbox".
Australia Script error: No such module "Infobox road/route/sandbox".
New Zealand

State Highway 2 marker

State Highway 2

Script error: No such module "Infobox road/route/sandbox".
Interstate |name=

Interstate 10 marker

Motorway 10

Script error: No such module "Infobox road/route/sandbox".
Interstate (Infobox road small)

Interstate 95 marker Interstate 95 marker

Interstate 95

Script error: No such module "Infobox road/route/sandbox".
France

Autorute A1 marker

Autorute A1

Script error: No such module "Infobox road/route/sandbox".
UK

A303 marker

A303

Script error: No such module "Infobox road/route/sandbox".
Brazil

SP-052 marker

SP-052

Script error: No such module "Infobox road/route/sandbox".
Chile

Route 5 marker Route 5 marker Route 5 marker

Route 5

Script error: No such module "Infobox road/route/sandbox".
BC

Highway 16 marker Highway 16 marker

Highway 16

Script error: No such module "Infobox road/route/sandbox".
Saskatchewan

Saskatchewan Rural Municipal Route.svg

Highway 600 marker

Highway 600

Script error: No such module "Infobox road/route/sandbox".
Quebec

Autoroute 35 marker

Autoroute 35

Script error: No such module "Infobox road/route/sandbox".
Ontario

Highway 407 marker

Highway 407

Script error: No such module "Infobox road/route/sandbox".
ON Secondary

Highway 522 marker

Highway 522

Script error: No such module "Infobox road/route/sandbox".
ON Tertiary

Highway 800 marker

Highway 800

Script error: No such module "Infobox road/route/sandbox".
NWT

Inuvik–Tuktoyaktuk Highway marker

Inuvik–Tuktoyaktuk Highway

Script error: No such module "Infobox road/route/sandbox".
Manitoba

Provincial Trunk Highway 3 marker

Provincial Trunk Highway 3

Script error: No such module "Infobox road/route/sandbox".
Tennessee Dual

State Route 1 marker State Route 1 marker

State Route 1

Script error: No such module "Infobox road/route/sandbox".
DE/MD Dual

Route 54 marker Route 54 marker

Route 54

Script error: No such module "Infobox road/route/sandbox".
Puerto Rico type=PR

Highway 1 marker Highway 1 marker Highway 1 marker Highway 1 marker

Highway 1

Script error: No such module "Infobox road/route/sandbox".
Puerto Rico type=Urban

Highway 1 marker

Highway 1

Script error: No such module "Infobox road/route/sandbox".
Wisconsin

State Trunk Highway 243 marker State Trunk Highway 243 marker

State Trunk Highway 243

Script error: No such module "Infobox road/route/sandbox".
North Carolina

Georgia State Route 246 and North Carolina Highway 106 marker Georgia State Route 246 and North Carolina Highway 106 marker

Georgia State Route 246 and
North Carolina Highway 106

Script error: No such module "Infobox road/route/sandbox".
Nevada BLSR

State Route 660 marker State Route 660 marker

State Route 660

Script error: No such module "Infobox road/route/sandbox".
Utah BLSR

State Route 120 marker State Route 120 marker

State Route 120

Script error: No such module "Infobox road/route/sandbox".
Texas Both

State Highway 1 marker State Highway 1 marker

State Highway 1

Script error: No such module "Infobox road/route/sandbox".
Texas tollway

Pres. George Bush Turnpike marker

Pres. George Bush Turnpike

Script error: No such module "Infobox road/route/sandbox".
1926 USH

U.S. Route 6 marker

U.S. Route 6

Script error: No such module "Infobox road/route/sandbox".
1948 USH

U.S. Route 40 marker

U.S. Route 40

Script error: No such module "Infobox road/route/sandbox".
Special route

Business plate.svg

U.S. Route 78 Business marker

U.S. Route 78 Business

Script error: No such module "Infobox road/route/sandbox".
Special route (style=small)

Business plate.svg

Business US Highway 131 marker

Business US Highway 131

Script error: No such module "Infobox road/route/sandbox".
Alaska |marker_image=

Circle sign 2.svg

Alaska Route 2

Script error: No such module "Infobox road/route/sandbox".
DC

District of Columbia Route 295 marker

District of Columbia Route 295

Script error: No such module "Infobox road/route/sandbox".
Mexico

Federal Highway 40D marker

Federal Highway 40D

Script error: No such module "Infobox road/route/sandbox".
Sonora

State Highway 149 marker

State Highway 149

Script error: No such module "Infobox road/route/sandbox".
GRR

Great River Road marker

Great River Road

Script error: No such module "Infobox road/route/sandbox".
Tour

Lake Michigan Circle Tour marker

Lake Michigan Circle Tour

Script error: No such module "Infobox road/route/sandbox".
Turnpike

Kansas Turnpike marker

Kansas Turnpike

Script error: No such module "Infobox road/route/sandbox".
County road

County Road Z36 marker

County Road Z36

Script error: No such module "Infobox road/route/sandbox".
Parish road

Parish Road 16 marker

Parish Road 16

Script error: No such module "Infobox road/route/sandbox".
CSAH

County State-Aid Highway 81 marker

County State-Aid Highway 81

Script error: No such module "Infobox road/route/sandbox".
Secondary

Secondary Highway 206 marker

Secondary Highway 206

Script error: No such module "Infobox road/route/sandbox".
Supplemental

Route BB marker

Route BB

Script error: No such module "Infobox road/route/sandbox".
Oregon

Oregon Route 35 marker

Oregon Route 35

Script error: No such module "Infobox road/route/sandbox".
Oregon Highway

John Day Highway No. 5

Script error: No such module "Infobox road/route/sandbox".
Belgium

National Route 1 marker

National Route 1

Script error: No such module "Infobox road/route/sandbox".
Belgium

E19 marker

E19

Script error: No such module "Infobox road/route/sandbox".

local p = {} 

local format = mw.ustring.format
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs	
local parserModule = require 'Module:Road data/parser'
local parser = parserModule.parser

local function banner(args, style)
	if args.marker_image then return nil end
	
	local bannerSize
		if style == 'small' then
			bannerSize = "40px"
		else
			bannerSize = "70px"
		end
	
	local shield = parser(args, 'banner')
	local alt = parser(args, 'banner')

	if not shield or shield == '' then
		return nil
	else
		return string.format('[[File:%s|%s|alt=%s]]', shield, bannerSize, alt)
	end
end



local function shield(args, style)

	if args.marker_image then return args.marker_image end
	
	local horizontalSize
	local verticalSize
		if style == 'small' then
			horizontalSize = "90x40px"
			verticalSize = "40x90px"
		else
			horizontalSize = "150x70px"
			verticalSize = "70x150px"
		end

	local shield = parser(args, 'shieldmain') or parser(args, 'shield') or ''
	
	local label = parser(args, 'name') or parser(args, 'abbr') or ''
	local alt = label .. ' marker'
	local orientation = parser(args, 'orientation')
	
	local function simpleSize(args)
		if orientation and orientation == 'upright' then
			return verticalSize
		else
			return horizontalSize
		end
	end
	
	local function shield_size(image_name, orientation)
		local image = 'File:' .. image_name
		local title = mw.title.new(image)

		local width = title.file.width
		local height = title.file.height
		
		if (orientation and orientation == 'upright') or height > width then
			return verticalSize
		else
			return horizontalSize
		end
	end
	
	
	
	if not shield or shield == '' then
		return nil
	elseif type(shield) == 'table' then
		local res = {}
		local sizes = {}
		for i,v in ipairs(shield) do
			sizes[i] = v
			res[i] = string.format('[[File:%s|%s|alt=%s]]', v, shield_size(v), alt)
		end
    	return table.concat(res, ' ')
	else
		return string.format('[[File:%s|%s|alt=%s]]', shield, simpleSize(args), alt)
	end
end

-- Links/abbreviations
local function name(args)
	local name = args.name or parser(args, 'name') or parser(args, 'abbr')
	return name
end

function p._routeInfo(args)
	
	local style = args.style
	local banner = banner(args, style)
	local shield = shield(args, style)
	local name = name(args)

	if not args.type and not args.route and not args.name and not args.marker_image then
		local container = nil
	else local container = mw.html.create('div'):cssText('text-align:center;')
		if shield == nil or args.marker_image == 'none' or args.name and not args.marker_image and not args.type and not args.route then 
			container:tag('p'):cssText('margin:0.1em;'):wikitext(name)
		elseif args.marker_image ~= '' and args.name == '' or args.name == nil and not args.type and not args.route then
			container:tag('p'):cssText('margin:0.1em;'):wikitext(shield)
		elseif args.country == 'AUS' then
			container:tag('p'):cssText('margin:0.1em;'):wikitext(name)
			container:tag('p'):cssText('margin:0.1em 0 0 0;'):wikitext(shield)
		else
			container:tag('p'):cssText('margin:0.1em 0 0 0;'):wikitext(banner)
			container:tag('p'):cssText('margin:0 0 0.1em;'):wikitext(shield)
			container:tag('p'):cssText('margin:0.1em;'):wikitext(name)
		end
		return tostring(container)
	end
end

function p.routeInfo(frame)
	local args = getArgs(frame)
	return p._routeInfo(args);
end

return p