Module:Sandbox/BrandonXLF/3

This is an old revision of this page, as edited by BrandonXLF (talk | contribs) at 05:27, 14 August 2024. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

-- Sandbox, do not delete
require('strict')

local p = {}

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

local types = {
	TCH = '[[File:TCH-blank.svg|15px]] [[Trans-Canada Highway]]',
	Yellowhead = '[[File:Yellowhead Blank.svg|15px]] [[Yellowhead Highway]]',
	['2'] = 'Interprovincial Highway 2'
}

local function route(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

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

local function nav(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 .. route(route, routeType, routeLoc, currProvince)
		
		index = index + 1
	until not args[prefix .. index]
	
	return label .. (index - 1 > 1 and 'routes' or 'route') .. '\n' .. out
end

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

function p.main(frame)
	local args = getArgs(frame)
	
	local type = args.type
	local route = args.curr
	local routeType = args.curr_type
	local routeLoc = args.curr_province
	
	local prev, prevWord = nav('prev', routeLoc, args)
	local next, nextWord = nav('next', routeLoc, args)
	
	return string.format(
		frame:preprocess(
			[[{{s-start}}
			|-
			! colspan=3 | %s
			|- style="text-align: center;"
			| style="width: 30%%;" | Previous&nbsp;%s<br>%s
			| style="width: 30%%;" | %s
			| style="width: 30%%;" | Next&nbsp;%s<br>%s
			{{s-end}}]]
		),
		types[type] or args.title or error('Type or title missing'),
		prevWord,
		prev,
		route(route, routeType, routeLoc, routeLoc),
		nextWord,
		next
	)
end

return p