Jump to content

Module:Jct/city/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Happy5214 (talk | contribs) at 02:28, 17 April 2016 (Standardizing "on deploy" comments). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

local concat = table.concat
local insert = table.insert

local state

local function stateName(args)
	local data = mw.loadData("Module:Jct/statename/sandbox") -- ON DEPLOY: Change to main module
	local abbr = args.state or args.province
	return data[args.country][abbr]
end

local function location(args, num)
	local city = args["city" .. num]
	local location = args["location" .. num]
	local areadab = args["areadab" .. num]
	local countydab = args["countydab" .. num]
	
	if location then
		return location
	end
	
	local parts = {}
	
	insert(parts, "[[" .. city)
	if areadab then
		insert(parts, " (" .. areadab .. ")")
	end
	if countydab then
		insert(parts, ", " .. countydab .. " County")
	end
	if state then
		insert(parts, ", " .. state)
	end
	
	insert(parts, "|" .. city .. "]]")
	return concat(parts)
end

function p.city(args)
	state = stateName(args)
	local cities = {}
	local locationCount = 1
	while args['city' .. locationCount] or args['location' .. locationCount] do
		insert(cities, location(args, locationCount))
		locationCount = locationCount + 1
	end
	return concat(cities, ', ')
end

return p