Jump to content

Module:Infobox road/color/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Fredddie (talk | contribs) at 09:44, 18 February 2021 (refactor). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {} 

local format = mw.ustring.format
local lower = mw.ustring.lower
local getArgs = require('Module:Arguments').getArgs	
local parser = require("Module:Road data/parser").parser
local countryMask = require "Module:Infobox road/meta/mask/country"

function p.color(frame)
	local pframe = frame:getParent()
	local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
	
	local function emptyParam(param)
		local empty = {[''] = true, ['¬'] = true}
		if not(param) or empty[param] then
			return nil
		else
			return param
		end
	end
	
	local state = args.state
	state = emptyParam(state)
	local province = args.province
	province = emptyParam(province)
	local type = args.type

	local countryArg = args.country
	countryArg = emptyParam(countryArg)
	local stateParam = state or province
	local countryLookup = countryMask._country(stateParam, countryArg)
	
	if not(stateParam) then
		return countryArg
	elseif not(countryArg)
		then return "default"
	else return countryLookup
	end
end