Jump to content

Module:Jctint/USA

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Chinissai (talk | contribs) at 15:23, 15 May 2016 (Created page with 'local p = {} local format = mw.ustring.format local concat = table.concat local insert = table.insert local roadDataModule = require("Module:Road data") local...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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