rowString = rowString .. '\n|' .. selectRank
selectCount = selectCount + 1
end
rowString = rowString .. '\n|' .. v[2] -- rank
lastRank = v[2]  
local move = v[3]
if move < 0 and math.abs( move ) == math.abs( v[2] ) then -- new teams in ranking: move = -ranking
change = :expandTemplate{ title = 'new entry' }
elseif move == 0 then -- if no change in ranking
change = :expandTemplate{ title = 'steady' }
elseif move < 0 then -- if ranking down
change = :expandTemplate{ title = 'decrease' } .. ' ' .. math.abs(move)
elseif move > 0 then -- if ranking up
change = :expandTemplate{ title = 'increase' } .. ' ' .. move
end
rowString = rowString .. '||' .. change  
--[[ for _,u in pairs(data.alias) do
if u[2]==v[1] then
code = u[1] -- if alias (country code) then use country name as key
break
end
end
--TODO reorganise the following with better logic
-- template to display flag icon and team link (e.g. fb, fbw, bk, ih)
e.g. "FIFA World Rankings" = 'fb', "FIFA Women's World Rankings" 'fbw',
"FIBA World Rankings" = 'bk', "IIHF World Ranking" = 'ih'
tries with country code, then if error, tried with country name
local countryTemplate = data.templates['flagged_team_link']
local flagVariant = ""
if data.templates.flagvar and data.templates.flagvar[code] then
flagVariant = data.templates.flagvar[code]
end
local countryIconString = :expandTemplate{ title = countryTemplate, args = {code, flagVariant} } -- country  
local _,test = string.gsub( countryIconString, "Template:Country data", "") -- page does not exist
if test == 1 then -- if error try country name
countryIconString = :expandTemplate{ title = countryTemplate, args = {v[1]} }
--countryIconString = "testing"
else
-- countryIconString = "exists"
end  
rowString = rowString .. '\n||' .. countryIconString  
local points = ""
if v[4] then points = v[4] end
rowString = rowString .. '||' .. points -- country for now, later points
outputString = outputString .. rowString
end
end
end  
-- add footer rows
count = 0
local footer = {}
while count < 5 do
count = count + 1
if templateArgs['footer'..count] then
footer[count] = templateArgs['footer'..count]
footer[count] = p.replaceKeywords(footer[count])
outputString = outputString .. '\n|-\n| |' .. footer[count]
end
end  
outputString = outputString .. "\n|}"  
return outputString  
end  
function p.replaceKeywords(keyword)
keyword = string.gsub( keyword, "INSERT_UPDATE_DATE", getDate)
keyword = string.gsub( keyword, "INSERT_LAST_DATE", getDate("LAST"))
if string.find(keyword, "INSERT_REFERENCE") then
keyword = string.gsub( keyword, "INSERT_REFERENCE", addReference(mw.getCurrentFrame))
end
return keyword
end  
--ranking= -- ranking to display (e.g. FIFA World Rankings)
|first= |last= -- first and last ranking to display (defaults 1-10)  
function p.list  
getArgs -- returns args table having checked for content
loadData
local ranking = .args[1]  
local first = tonumber(.args['2']) or 1
local last = tonumber(.args['3']) or 10  
return table(, ranking, first, last)
end  
--ranking |country |span
-- ranking - the ranking to display (e.g. FIFA World Rankings)
-- country - country table is centred around
-- span= - rows to display above and below country  
function p.list2  
getArgs -- returns args table having checked for content
loadData
local ranking = .args[1]
local first, last = 1,10
local country = .args[2] -- name or code of country to table around
local span = .args[3] or 2 -- number of rows to display above and below country (default:2)  
if string.len(country) == 3 then -- if three letter country code
for _,u in pairs(data.alias) do
if u[1]==country then
country = u[2] -- if country code then use country name
break
end
end
end
for k,v in pairs(data.rankings) do -- find position of country in rankings
if v[1] == country then
first = v[2]-span
last = v[2]+span
end
end  
return table(, ranking, first, last)
end  
return p