Module:phi-placelist
Appearance
- The following documentation is located at Module:phi-placelist/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module is used by {{list:places in the Philippines/en}}
.
Data modules
[edit]- phi-placelist/data/BARMM
- phi-placelist/data/BARMM/Special Geographic Area
- phi-placelist/data/CAR
- phi-placelist/data/CAR/Baguio
- phi-placelist/data/CAR/Benguet
- phi-placelist/data/CAR/Mountain Province
- phi-placelist/data/I/Ilocos Norte
- phi-placelist/data/I/Ilocos Sur
- phi-placelist/data/I/La Union
- phi-placelist/data/III/Nueva Ecija
- phi-placelist/data/IV-A
- phi-placelist/data/IV-A/Laguna
- phi-placelist/data/IV-A/Quezon
- phi-placelist/data/NCR
- phi-placelist/data/NCR/Caloocan
- phi-placelist/data/NCR/Manila
- phi-placelist/data/NCR/Parañaque
- phi-placelist/data/NCR/Pasay
- phi-placelist/data/NCR/Pasig
- phi-placelist/data/NCR/Quezon City
- phi-placelist/data/XI
- phi-placelist/data/XI/Davao City
- phi-placelist/data/XI/Davao Oriental
- phi-placelist/documentation
-- https://stackoverflow.com/a/12674376/14021404
local function getKeysOfTable(table)
local keyset={}
local n=0
for k,v in pairs(table) do
n=n+1
keyset[n]=k
end
return keyset;
end
-----------------
-- Main function
local function getTableFromData( args )
local inputtedDivisions = {} -- save here the inputted divisions, in order of less specific to more specific
local level = 0
while ( level < 6 ) do
argLevel = args[level]
if argLevel ~= nil then -- get all positional arguments from 0 to 6
inputtedDivisions[level] = argLevel
end
level = level + 1
end
-- get the division from data modules
local list = {}
local _region = ""
for i, v in ipairs( inputtedDivisions ) do
if (i == 1 and #inputtedDivisions == 1) then -- if the first and only the first one, get from region data module
list = require("Module:phi-placelist/data/" .. v)
elseif (i == 1) then --if the first one, it is the region, store it
_region = v
elseif (i == 2) then --if the second one, get from data module
list = require("Module:phi-placelist/data/" .. _region .. "/" .. v)
else
list = list[v]
end
end
-- error check so that the last inputted parameter is one division up
if type(list) ~= "table" then
error(inputtedDivisions[#inputtedDivisions] .. " has no divisions already. Just remove that part.")
end
-- get the keys from the data module & prepare for template call
local divisionName = list["divisions"]
list["divisions"] = nil
local excludesText = nil
if list["excludes"] ~= nil then
excludesText = list["excludes"]
end
local finalList = getKeysOfTable(list)
-- I am mixed on whether to autosort the list. For now, sure.
table.sort(finalList)
return finalList, inputtedDivisions, divisionName, excludesText
end
local a = {}
-- for use in the definition lines
function a.linksInDefinition( frame )
local args = frame:getParent().args
local templateToCall = args["type"]
if templateToCall == nil then
templateToCall = "coordinate terms"
end
-- get table
local finalList, inputtedDivisions, divisionName, excludesText = getTableFromData(args)
-- prepare parameters for the {{coordinate terms}} (or others) template call
table.insert(finalList, 1, "en") -- the language parameter
finalList["lb"] = divisionName .. " of " .. inputtedDivisions[#inputtedDivisions] -- the label parameter
if excludesText ~= nil then
finalList["lb"] = finalList["lb"] .. " <small>(excluding " .. excludesText .. ")</small>"
end
return frame:expandTemplate{ title = templateToCall , args = finalList }
end
-- for use in `See also` headings
function a.linksInSeeAlso( frame )
local args = frame:getParent().args
-- get table
local finalList, inputtedDivisions, divisionName, excludesText = getTableFromData(args)
-- prepare parameters for the {{col3}} template call
table.insert(finalList, 1, "en") -- the language parameter
local label = divisionName .. " of " .. inputtedDivisions[#inputtedDivisions] -- label
if excludesText ~= nil then
label = label .. " <small>(excluding " .. excludesText .. ")</small>"
end
-- no need to use {{q}} to reduce lua usage
return "(''" .. label .. "''): " .. frame:expandTemplate{ title = "col3-u" , args = finalList }
end
return a;