Module:Infobox road/sections

MyWikiBiz, Author Your Legacy — Thursday December 26, 2024
Jump to navigationJump to search

Documentation for this module may be created at Module:Infobox road/sections/doc

local p = {}

local function terminus_a(num, args)
	local direction = args["direction_a" .. num] or args.direction_a or ''
	local label
	if direction ~= '' then
		label = direction .. " end:"
	else
		label = "From:"
	end
	local data = args["terminus_a" .. num]
	return label, data
end

local function terminus_b(num, args)
	local direction = args["direction_b" .. num] or args.direction_b or ''
	local label
	if direction ~= '' then
		label = direction .. " end:"
	else
		label = "To:"
	end
	local data = args["terminus_b" .. num]
	return label, data
end

function p._section(num, args)
	local lead = --[[5 * num +]] 1
	local parameters = {["label" .. (lead + 1)] = "Length:", ["label" .. (lead + 3)] = "Major<br>junctions:", child = "yes", decat = "yes", labelstyle = "text-align:right"}
	local data = {}
	
	local title = args["section" .. num] or "Section " .. num
	--parameters["header" .. lead] = title
	parameters.title = title
	
	local lengthModule = require "Module:Infobox road/length"
	data[lead + 1] = lengthModule._length(num, args)
	parameters["label" .. (lead + 2)], data[lead + 2] = terminus_a(num, args)
	data[lead + 3] = args["junction" .. num]
	parameters["label" .. (lead + 4)], data[lead + 4] = terminus_b(num, args)
	
	local hasData = false
	for k,v in pairs(data) do
		hasData = true
		break
	end
	if not(hasData) then
		return ''
	end
	
	for k,v in pairs(data) do
		parameters["data" .. k] = v
	end
	
	local infoboxModule = require 'Module:Infobox'
	return infoboxModule.infobox(parameters)
end

function p.section(frame)
	local pframe = frame:getParent()
	local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
	local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
	
	local num = config.num
	return p._section(num, args)
end

local function loop(args)
	local ring_road = args.ring_road or ''
	if ring_road ~= '' then
		return "[[Ring road]] around " .. ring_road
	end
	local beltway_city = args.beltway_city or ''
	if beltway_city ~= '' then
		return "[[Beltway]] around " .. beltway_city
	end
	local orbital = args.orbital or ''
	if orbital ~= '' then
		return "[[Orbital road|Orbital]] around " .. orbital
	end
	local loop = args.loop or ''
	if loop ~= '' then
		return "[[Loop road|Loop]] around " .. loop
	end
	local tloop = args.tloop or ''
	if tloop == 'none' then
		return "Tourist loop"
	elseif tloop ~= '' then
		return "Tourist loop around " .. tloop
	end
	return nil
end

function p._main(args)
	local lead = --[[5 * num +]] 1
	local parameters = {["label" .. (lead + 3)] = "&nbsp;", child = "yes", decat = "yes", labelstyle = "text-align:right"}
	local data = {}
	
	local title = args.section0 or "Major junctions"
	--parameters["header" .. lead] = title
	parameters.title = title
	
	data[lead + 1] = loop(args)
	parameters["label" .. (lead + 2)], data[lead + 2] = terminus_a('', args)
	data[lead + 3] = args.junction
	parameters["label" .. (lead + 4)], data[lead + 4] = terminus_b('', args)
	
	local hasData = false
	for k,v in pairs(data) do
		hasData = true
		break
	end
	if not(hasData) then
		return ''
	end
	
	for k,v in pairs(data) do
		parameters["data" .. k] = v
	end
	
	local infoboxModule = require 'Module:Infobox'
	return infoboxModule.infobox(parameters)
end

function p.main(frame)
	local pframe = frame:getParent()
	local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
	local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
	
	return p._main(args)
end

return p