وحدة:Infobox road/route

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 خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
No parameters خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Only |marker_image= خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Florida |marker_image=none خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Only |name=

Autoroute 10

خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Australia خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
New Zealand خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Interstate |name=

Motorway 10

خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Interstate (Infobox road small) خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
France خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
UK خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Brazil خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Chile خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
BC خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Saskatchewan خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Quebec خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Ontario خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
ON Secondary خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
ON Tertiary خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
NWT خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Manitoba خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Tennessee Dual خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
DE/MD Dual خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Puerto Rico type=PR خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Puerto Rico type=Urban خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Wisconsin خطأ لوا في السطر 66: attempt to compare two nil values. خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
North Carolina خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Nevada BLSR خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Utah BLSR خطأ لوا في السطر 66: attempt to compare two nil values. خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Texas Both خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Texas tollway خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
1926 USH

خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
1948 USH خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Special route خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Special route (style=small)

Business plate.svg

ملف:US 131.svg

Business US Highway 131

خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Alaska |marker_image= خطأ لوا في السطر 116: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
DC

DC 295 marker

DC 295

خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Mexico خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Sonora خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
GRR خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Tour

ملف:Lake Michigan Circle Tour.svg

Lake Michigan Circle Tour

خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Turnpike خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
County road خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Parish road خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
CSAH خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Secondary خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Supplemental خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Oregon خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Oregon Highway خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Belgium خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".
Belgium خطأ لوا في السطر 107: bad argument #1 to 'wikitext' (string or number expected, got boolean). خطأ: لا توجد وحدة بهذا الاسم "Infobox road/route/sandbox".

local p = {} 

local format = mw.ustring.format
require('strict')
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 = "72px"
		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 = "154x72px"
			verticalSize = "72x154px"
		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

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

	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; display: inline-block; vertical-align: baseline; line-height: 0;')
		container:tag('p'):cssText('margin:0.1em 0 0 0;'):wikitext(banner)
		container:tag('p'):cssText('margin:0 0 0.1em;'):wikitext(shield)
	return tostring(container)
	end
end

function p.shields(frame)
	local args = getArgs(frame)
	return p._shields(args);
end


function p._names(args)
	local name = name(args)
	return name
end

function p.names(frame)
	local args = getArgs(frame)
	return p._names(args);
end

return p