Difference between revisions of "Module:Jct/city"
Jump to navigation
Jump to search
blackwiki>Happy5214 (Sync with sandbox: Allow unlimited locations and calling from Module:Jct) |
blackwiki>Happy5214 (July update: Use local variables for table.concat and table.insert; rename table for AUS state abbreviations; use reformatted data module for state names) |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
| + | |||
| + | local concat = table.concat | ||
| + | local insert = table.insert | ||
local state | local state | ||
local function stateName(args) | local function stateName(args) | ||
| − | local | + | local AUSabbrs = {NT = "Northern Territory", WA = "Western Australia"} |
| − | local data = mw.loadData("Module:Jct/statename | + | local data = mw.loadData("Module:Jct/statename") |
local abbr = args.state or args.province | local abbr = args.state or args.province | ||
local country = args.country | local country = args.country | ||
if country == 'AUS' then | if country == 'AUS' then | ||
| − | return | + | return AUSabbrs[abbr] or data[abbr] |
else | else | ||
| − | return data | + | return data[abbr] |
end | end | ||
end | end | ||
| Line 34: | Line 37: | ||
if location then | if location then | ||
| − | + | insert(parts, location) | |
| − | return | + | return concat(parts) |
end | end | ||
| − | + | insert(parts, "[[" .. city) | |
if areadab then | if areadab then | ||
| − | + | insert(parts, " (" .. areadab .. ")") | |
end | end | ||
if countydab then | if countydab then | ||
| − | + | insert(parts, ", " .. countydab .. " County") | |
end | end | ||
if state then | if state then | ||
| − | + | insert(parts, ", " .. state) | |
end | end | ||
| − | + | insert(parts, "|" .. city .. "]]") | |
| − | return | + | return concat(parts) |
end | end | ||
| Line 59: | Line 62: | ||
repeat | repeat | ||
local location = location(args, locationCount) | local location = location(args, locationCount) | ||
| − | + | insert(cities, location) | |
local empty = (location == '') | local empty = (location == '') | ||
locationCount = locationCount + 1 | locationCount = locationCount + 1 | ||
until empty | until empty | ||
| − | return | + | return concat(cities) |
end | end | ||
return p | return p | ||
Revision as of 07:53, 3 July 2014
Documentation for this module may be created at Module:Jct/city/doc
local p = {}
local concat = table.concat
local insert = table.insert
local state
local function stateName(args)
local AUSabbrs = {NT = "Northern Territory", WA = "Western Australia"}
local data = mw.loadData("Module:Jct/statename")
local abbr = args.state or args.province
local country = args.country
if country == 'AUS' then
return AUSabbrs[abbr] or data[abbr]
else
return data[abbr]
end
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 not(city or location) then
return ''
end
local parts
if num == 1 then
parts = {" – "}
else
parts = {", "}
end
if location then
insert(parts, location)
return concat(parts)
end
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
repeat
local location = location(args, locationCount)
insert(cities, location)
local empty = (location == '')
locationCount = locationCount + 1
until empty
return concat(cities)
end
return p