Difference between revisions of "Module:Jct/city"
Jump to navigation
Jump to search
blackwiki>Rschen7754 m (Protected Module:Jct/city: High-risk Lua module ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite))) |
blackwiki>Happy5214 (Sync with sandbox: Allow unlimited locations and calling from Module:Jct) |
||
| Line 53: | Line 53: | ||
end | end | ||
| − | function p.city( | + | function p.city(args) |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
state = stateName(args) | state = stateName(args) | ||
local cities = {} | local cities = {} | ||
| − | + | local locationCount = 1 | |
| − | + | repeat | |
| − | + | local location = location(args, locationCount) | |
| + | table.insert(cities, location) | ||
| + | local empty = (location == '') | ||
| + | locationCount = locationCount + 1 | ||
| + | until empty | ||
return table.concat(cities) | return table.concat(cities) | ||
end | end | ||
return p | return p | ||
Revision as of 02:15, 5 June 2014
Documentation for this module may be created at Module:Jct/city/doc
local p = {}
local state
local function stateName(args)
local dualabbrs = {NT = "Northern Territory", WA = "Western Australia"}
local data = mw.loadData("Module:Jct/statename/data")
local abbr = args.state or args.province
local country = args.country
if country == 'AUS' then
return dualabbrs[abbr] or data.statenames[abbr]
else
return data.statenames[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
table.insert(parts, location)
return table.concat(parts)
end
table.insert(parts, "[[" .. city)
if areadab then
table.insert(parts, " (" .. areadab .. ")")
end
if countydab then
table.insert(parts, ", " .. countydab .. " County")
end
if state then
table.insert(parts, ", " .. state)
end
table.insert(parts, "|" .. city .. "]]")
return table.concat(parts)
end
function p.city(args)
state = stateName(args)
local cities = {}
local locationCount = 1
repeat
local location = location(args, locationCount)
table.insert(cities, location)
local empty = (location == '')
locationCount = locationCount + 1
until empty
return table.concat(cities)
end
return p