Jump to content

Module:Interprovincial highway

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by BrandonXLF (talk | contribs) at 13:51, 14 August 2024 (Module for the future Template:Interprovincial highway). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

require('strict')

local getArgs = require('Module:Arguments').getArgs
local parserModule = require('Module:Road data/parser')
local parser = parserModule.parser

local function makeRoute(route, routeType, routeLoc, currProvince)
	local out = ''
	
	local parserArgs = {
		route = route,
		type = routeType,
		province = routeLoc
	}
	
	local shield = parser(parserArgs, 'shieldmain') or parser(parserArgs, 'shield') or ''
	
	local label = parser(parserArgs, 'name') or parser(parserArgs, 'abbr') or ''
	label = (routeLoc ~= currProvince and (routeLoc .. ' ') or '') .. label

	local link = parser(parserArgs, 'link')
	local alt = label .. ' marker'
	
	if type(shield) == 'table' then
		shield = shield[1]
	end
	
	out = out ..  string.format('[[File:%s|15px|alt=%s]]', shield, alt)
	
	if not link or link == '' then
		out = out  .. ' ' .. label
	else
		out = out  .. ' ' .. string.format('[[%s|%s]]', link, label)
	end
	
	return "'''" .. out .. "'''"
end

local function makeNav(prefix, label, currProvince, args)
	local index = 1
	local out = ''
	
	repeat
		local route = args[prefix .. index] or (index == 1 and args[prefix] or '')
		local routeType = args[prefix .. index .. '_type'] or (index == 1 and args[prefix .. '_type'] or '')
		local routeLoc = args[prefix .. index .. '_province'] or (index == 1 and args[prefix .. '_province'] or '')
		
		if index ~= 1 then
			out = out .. '<hr>'
		end
		
		out = out .. makeRoute(route, routeType, routeLoc, currProvince)
		
		index = index + 1
	until not args[prefix .. index]
	
	return label .. ' ' .. (index - 1 > 1 and 'routes' or 'route') .. '<br>' .. out
end

local p = {}

function p.route(frame)
	return makeRoute(
		frame.args[1],
		frame.args.type,
		frame.args.province,
		frame.args.current_province or frame.args.province
	)
end

function p.nav(frame)
	return makeNav(
		frame.args[1],
		frame.args.label,
		frame.args.current_province,
		getArgs(frame, { parentOnly = true })
	)
end

return p