Module:Jctint/USA
Appearance
![]() | This Lua module is used on approximately 12,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
This modules implements the US region specific Jctint templates.
local p = {}
local format = mw.ustring.format
local concat = table.concat
local insert = table.insert
local roadDataModule = require("Module:Road data")
local function sub_special(args, paramPrefix, subType, textSuffix)
local subs = {}
-- Retrieve wikilinks for subdivisions.
for i = 1,4 do
local sub = args[paramPrefix .. i]
if sub then
local savedSub= args[subType]
args[subType] = sub
local locns = roadDataModule.locations(args, "jctint")
args[subType] = savedSub
subs[i] = locns[subType]
end
end
if subs[1] and subs[2] then
local textParts = {}
insert(textParts, format("%s–%s", subs[1], subs[2]))
if subs[3] then
insert(textParts, format("–<br>%s", subs[3]))
end
if subs[4] then
insert(textParts, format("–%s", subs[4]))
end
insert(textParts, textSuffix)
return concat(textParts)
else
return args[paramPrefix .. "_special"]
end
end
function p._jctint(args)
-- Extra parameters
args.primary_topic = "no"
args.sub1name = args.sub1name or "County" -- TODO transition
args.sub1_special = sub_special(args, "county", "sub1", "<br>county line")
args.sub2_special = sub_special(args, "location", "sub2", " line")
args.unitdef = "mi"
-- Parameters to be renamed
local paramSubst = {
region_special = "state_speicial",
regionspan = "sspan",
sub1 = "county",
sub1span = "cspan",
sub1dab = "ctdab",
sub2 = "location",
unit = "mile",
unit2 = "mile2",
unit_ref = "mile_ref",
uspan = "mspan"
}
-- Rename parameters.
for tgt,src in pairs(paramSubst) do
args[tgt] = args[src]
args[src] = nil
end
-- Parameters to be removed
local nilParams = {
"county1", "county2", "county3", "county4", "county_special",
"location1", "location2", "location3", "location4", "location_special"
}
-- Remove parameters.
for _,param in ipairs(nilParams) do
args[param] = nil
end
local coreModule = require("Module:Jctint/core")
return coreModule._jctint(args)
end
function p.jctint(frame)
-- Import module function to work with passed arguments
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
return p._jctint(args)
end
return p