Module:Infobox road/route

MyWikiBiz, Author Your Legacy — Friday November 22, 2024
Jump to navigationJump 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 Template:Tlx.

Output examples

Description Output Description Output
Florida Both (current output) Lua error at line 42: attempt to compare two nil values. Florida Both (intended output)

70px x70px

State Road 869

No parameters Only Template:Para
Florida Template:Para

State Road A1A

Only Template:Para

Autoroute 10

Australia

National Highway 31

70px

New Zealand Lua error at line 42: attempt to compare two nil values.
Interstate Template:Para Lua error at line 42: attempt to compare two nil values. Interstate (Infobox road small) Lua error at line 42: attempt to compare two nil values.
France Lua error at line 42: attempt to compare two nil values. UK Lua error at line 42: attempt to compare two nil values.
Brazil Lua error at line 42: attempt to compare two nil values. Chile Lua error at line 42: attempt to compare two nil values.
BC Lua error at line 42: attempt to compare two nil values. Saskatchewan

70px

70px

Highway 600

Quebec

70px

Autoroute 35

Ontario Lua error at line 42: attempt to compare two nil values.
ON Secondary Lua error at line 42: attempt to compare two nil values. ON Tertiary

70px

Highway 800

NWT

70px

Inuvik–Tuktoyaktuk Highway

Manitoba

Provincial Trunk Highway 3

Tennessee Dual Lua error at line 42: attempt to compare two nil values. DE/MD Dual Lua error at line 42: attempt to compare two nil values.
Puerto Rico type=PR Lua error at line 42: attempt to compare two nil values. Puerto Rico type=Urban Lua error at line 42: attempt to compare two nil values.
Wisconsin Lua error at line 42: attempt to compare two nil values. North Carolina Lua error at line 42: attempt to compare two nil values.
Nevada BLSR Lua error at line 42: attempt to compare two nil values. Utah BLSR Lua error at line 42: attempt to compare two nil values.
Texas Both Lua error at line 42: attempt to compare two nil values. Texas tollway

70px

Pres. George Bush Turnpike

1926 USH Lua error at line 42: attempt to compare two nil values. 1948 USH Lua error at line 42: attempt to compare two nil values.
Special route Lua error at line 42: attempt to compare two nil values. Special route Lua error at line 42: attempt to compare two nil values.
Alaska Template:Para

x70px

Alaska Route 2

DC Lua error at line 42: attempt to compare two nil values.
Mexico Lua error at line 42: attempt to compare two nil values. Sonora Lua error at line 42: attempt to compare two nil values.
GRR Lua error at line 42: attempt to compare two nil values. Tour Lua error at line 42: attempt to compare two nil values.
Turnpike Lua error at line 42: attempt to compare two nil values. County road Lua error at line 42: attempt to compare two nil values.
Parish road Lua error at line 42: attempt to compare two nil values. CSAH Lua error at line 42: attempt to compare two nil values.
Secondary Lua error at line 42: attempt to compare two nil values. Supplemental Lua error at line 42: attempt to compare two nil values.
Oregon Lua error at line 42: attempt to compare two nil values. Oregon Highway

John Day Highway No. 5

Belgium Lua error at line 42: attempt to compare two nil values. Belgium Lua error at line 42: attempt to compare two nil values.

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, bannerSize)
	if args.marker_image then return nil end
	
	if args.shielderr then return nil end
		
	local shield = parser(args, 'banner')
	if not shield or shield == '' then return nil end
	
	local alt = parser(args, 'banner')
	
	return string.format('[[File:%s|%s|alt=%s]]', shield, bannerSize, alt)
end



local function shield(args, shieldSize)
	if args.marker_image then return args.marker_image end

	local shield = parser(args, 'shieldmain') or parser(args, 'shield')
	
	if not shield or shield == '' then return nil end
	
	local label = parser(args, 'name') or parser(args, 'abbr') or ''
	local alt = label .. ' marker'
	local orientation = parser(args, 'orientation')
	
	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 shieldSize
		else
			return 'x' .. shieldSize
		end
	end
	
	if 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, shield_size(shield, orientation), 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, require('Module:Road data/size').size({style = style}))
	local shield = shield(args, require('Module:Road data/size').size({style = 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;')
			container:tag('p'):wikitext('')
		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