Module:Infobox road other

From the AARoads Wiki: Read about the road before you go
Jump to navigation Jump to search
local p = {}
local getArgs = require('Module:Arguments').getArgs
local util = require("Module:Road data/util")
local yesno = require('Module:Yesno')
local langModule = require('Module:Lang')
local routeModule = require("Module:Infobox road/route")
local parserModule = require("Module:Road data/parser")
local parser = parserModule.parser
local format = mw.ustring.format
local frame = mw.getCurrentFrame()

local function country(args)
	local state = args.state or args.province
	local country
	local countryModule = mw.loadData("Module:Road data/countrymask")
	local country = args.country or countryModule[state]
	
	return country
end

-- HEADER COLORS

function p.headerStyle(frame)
	local args = getArgs(frame)
	local header 
		if args.header_type == nil then
			header = args.header_type
		else
			header = string.lower(args.header_type)
		end
		
	local deleted = args.decommissioned or args.deleted or header == "former"
	local uc = header == "under construction" or header == "const" or header == "uc"
	local minor = header == "minor"
	local hist = header == "hist" or header == "historic" or header == "historical" or header == "scenic"

	if uc then
		return "header-uc"
	elseif minor then
		return "header-minor"
	elseif deleted and header == 'hist' or deleted and color == 'hist' then
		return "header-deleted-hist"
	elseif deleted then
		return "header-deleted"
	elseif hist then
		return "header-hist"
	else
		return "header-default"
	end
end


-- EXISTED

function p._existed(args)
	local formed = args.established or args.formed or args.completion_date or ''
	local deleted = args.decommissioned or args.deleted or ''
	
	if formed == '' then
		return nil
	elseif deleted == '' then
		return formed .. "–present"
	else
		return formed .. "–" .. deleted
	end
end

function p.existed(frame)
	local args = getArgs(frame)
	return p._existed(args)
end

-- TIME PERIOD

local function period(args)
	
	local infobox_args = {}
	
	infobox_args['bodystyle'] = 'display:inline-table;'
	infobox_args['child'] = 'yes'
	infobox_args['decat'] = 'yes'
	infobox_args['label1'] = "Time period"
	infobox_args['data1'] = args.time_period
	
	if args.time_period then
		infobox_args['label2'] = "Cultural significance"
		infobox_args['data2'] = args.significance
		infobox_args['label3'] = "Known for"
		infobox_args['data3'] = args.known_for
		infobox_args['label4'] = "Related routes"
		infobox_args['data4'] = args.related
	else
		infobox_args['label3'] = "Known for"
		infobox_args['data3'] = args.known_for
	end

	return frame:expandTemplate ({title='Infobox', args = infobox_args})
end

local function period_params(args)

	if args.time_period or args.known_for then
		return true
	else
		return false
	end
end

function p.period(frame)
	local args = getArgs(frame)
	
	if period_params(args) == false then
			return nil
		else
			return period(args)
		end
	end

-- ALLOCATION

local function allocation(args)
	local country = country(args)
	
	if country == "AUS" then
		return "[[Route number#Australia|Allocation]]"
		else return "Component<br>highways"
	end
end

function p.allocation(frame)
	local args = getArgs(frame)
	return allocation(args)
end


-- ROUTE INFORMATION HEADER

local function info(args)
	local period = period_params(args)
	local existed = args.established or args.formed or nil
	
	if period == true or existed ~= nil or args.section or args.length_mi or args.length_km or args.allocation or args.history or args.restrictions or args.tourist or args.status then
		return "Route information"
	else
		return nil
	end
end

function p.info(frame)
	local args = getArgs(frame)
	return info(args)
end

return p