Jump to content

Module:Jct/city and Module:Jct/city/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
rm space as there already is one
 
No edit summary
 
Line 4: Line 4:
local insert = table.insert
local insert = table.insert



local city
local location
local areadab
local countydab
local state
local state
local pageContainsLink


local function stateName(args)
local function stateName(args)
Line 19: Line 25:
end
end


local function location(args, num)
local function generateText(num, insertPrefix)
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
local parts
if num == 1 then
if insertPrefix then
parts = {"– "}
if num == 1 then
parts = {"– "}
else
parts = {", "}
else
parts = {", "}
end
end
end
Line 41: Line 40:
end
end
if not pageContainsLink then
insert(parts, "[[" .. city)
insert(parts, "[[" .. city)
if areadab then
insert(parts, " (" .. areadab .. ")")
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)
else
insert(parts, city)
return concat(parts)
end
end
end
if countydab then

insert(parts, ", " .. countydab .. " County")
local function _location(args, num, page)
city = args["city" .. num]
location = args["location" .. num]
areadab = args["areadab" .. num]
countydab = args["countydab" .. num]
if not(city or location) then
return ''
end
end
if state then
if pageContainsLink == false then
insert(parts, ", " .. state)
local place = city or location
local jctString = "{{jct/sandbox|" .. ".+" .. place .. ".+" .. "}}"
local linkString = generateText(num, false)
local firstPosition = strfind(page, linkString)
if firstPosition then
local secondPosition = strfind(page, linkString, firstPosition)
if secondPosition or string.find(page, jctString) then
pageContainsLink = true
end
end
end
end
return generateText(num, true)
insert(parts, "|" .. city .. "]]")
return concat(parts)
end
end


function p.city(args)
function p.city(args, page)
state = stateName(args)
state = stateName(args)
local cities = {}
local cities = {}
local locationCount = 1
local locationCount = 1
repeat
repeat
local location = location(args, locationCount)
local location = _location(args, locationCount, page)
insert(cities, location)
insert(cities, location)
local empty = (location == '')
local empty = (location == '')