Module:Jctint/MEX explained

local p =

local format = mw.ustring.formatlocal concat = table.concatlocal insert = table.insert

local roadDataModule = require("Module:Road data")

-- TODO transition-- begin transition code

-- local region_special = ]]

--local indep_city =

local sub1Config =

local sub1name =

local sub1span =

local subConfig =

local function sub_special(args, subTypeConfig, specialPrefix, subType) -- Find parameter. local subParam for _,p in ipairs(subTypeConfig) do if args[p .. 1] or args[p] then subParam = p break end end if not subParam then return args[specialPrefix .. "_special"] end local config = subConfig[subParam] or local subs = -- Retrieve wikilinks for subdivisions. local num = 1 while num

1 or args[subParam .. num] do -- Save parameters. local saved = saved[subType]= args[subType] args[subType] = args[subParam .. num] or num

1 and args[subParam] saved.sub1dab = args.sub1dab args.sub1dab = args["ctdab" .. num] or args.ctdab or num

1 and config.firstnonum and args.county saved.area = args.area args.area = not (config.nosub1dab and args.sub1dab) and (config.sub2area or args["area" .. num] or num

1 and config.firstnonum and args.area) local locns = roadDataModule.locations(args, "jctint", true) -- Restore parameters. args[subType] = saved[subType] args.sub1dab = saved.sub1dab args.area = saved.area subs[num] = locns[subType] num = num + 1 end if #subs > 1 then -- Construct wikitext for multiple subs. local textParts = insert(textParts, subs[1]) for i = 2, #subs do insert(textParts, "–") if i % 2 ~= 0 then -- Odd subs after first begin a new line. insert(textParts, "
") end insert(textParts, subs[i]) end local groupSuffix = args[specialPrefix .. "_group"] or config.group if groupSuffix then insert(textParts, format("%s%s", #subs % 2

0 and "
" or " ", groupSuffix)) end if #subs

2 then insert(textParts, " line") elseif #subs

3 then insert(textParts, " tripoint") elseif #subs

4 then insert(textParts, " quadripoint") else insert(textParts, " multipoint") end return concat(textParts) elseif #subs

1 and config.single then -- TODO transition -- Save parameters. local saved = saved[subType]= args[subType] args[subType] = args[subParam .. 1] or args[subParam] saved.sub1dab = args.sub1dab args.sub1dab = args.ctdab1 or args.ctdab or config.firstnonum and args.county saved.area = args.area args.area = not (config.nosub1dab and args.sub1dab) and (config.sub2area or args.area1 or config.firstnonum and args.area) local locns = roadDataModule.locations(args, "jctint") -- Restore parameters. args[subType] = saved[subType] args.sub1dab = saved.sub1dab args.area = saved.area return locns[subType] endend-- end transition code

local function trackedArray(arr) local origArr = arr arr = local mt = setmetatable(arr, mt) return arrend

function p._jctint(args) local sub1config = sub1Config[args.state] or "county" -- Tracked parameters local msgs = if args.type

"mplex" then insert(msgs, format("", "M")) end local blanks = for _,param in ipairs(blanks) do if args[param]

" " then insert(msgs, format("", "B")) break end end local spans = for _,param in ipairs(spans) do if args[param]

"1" then insert(msgs, format("", "S")) break end end local trackedParams = for key,param in pairs(trackedParams) do if args[param] then insert(msgs, format("", key)) end end

-- Track used arguments local origArgs = args args = trackedArray(args)

local lengthUnit = args.unitdef or "km" -- Extra parameters local moduleArgs = -- Parameters to be renamed local paramSubst = -- Redirect undefined arguments to passed arguments local mt = setmetatable(moduleArgs, mt)

moduleArgs.country = "USA" -- TODO transition -- begin transition code moduleArgs.primary_topic = "no" moduleArgs.sub1name = sub1name[args.state] or "County" moduleArgs.region_special = region_special[args.state] moduleArgs.region = mw.loadData("Module:Jct/statename")[args.state] -- Independent city local indepCityText = sub_special(moduleArgs,, "indep_city", "sub2") if not indepCityText and args.indep_city then local indepCity = args.indep_city local spec = indep_city[args.state] and (indep_city[args.state][indepCity] or indep_city[args.state].default) if spec then local link = format("%s%s%s", spec.linkprefix or "", indepCity, spec.linksuffix or "") local name = format("%s%s%s", spec.nameprefix or "", indepCity, spec.namesuffix or "") indepCityText = format("%s%s", spec.prefix or "", link, name) else -- Specialize independent city to the region. local cityLink = format('%s', indepCity, moduleArgs.region, indepCity) indepCityText = cityLink end args.indep_city = nil end moduleArgs.indep_city_special = indepCityText moduleArgs.sub1_special = sub_special(moduleArgs,, sub1config, "sub1") local sub2Config = if args.sub2param then insert(sub2Config, args.sub2param) end if sub2params[args.state] then for _,param in ipairs(sub2params[args.state]) do insert(sub2Config, param) end end insert(sub2Config, "location") moduleArgs.sub2_special = sub_special(moduleArgs, sub2Config, "location", "sub2") -- end transition code moduleArgs.unitdef = args.unitdef or "km"

-- Crossing if args.xing then local colType local colAlignType if args.xcspan

"3" then colType = "unitary" colAlignType = "unitary_align" elseif args.xcspan

"2" then colType = "indep_city_special" colAlignType = "indep_city_align" else colType = "sub2_special" colAlignType = "sub2_align" end moduleArgs[colType] = args.xing moduleArgs[colAlignType] = "center" end

local coreModule = require("Module:Jctint/core") local coreResult = coreModule._jctint(moduleArgs)

-- Report unused arguments local unusedArgs = for key,_ in pairs(origArgs) do insert(unusedArgs, key) end

local msg if #msgs > 0 then local page = mw.title.getCurrentTitle.prefixedText -- Get transcluding page's title msg = mw.ustring.gsub(concat(msgs), "%%page%%", page) end return coreResult .. (msg or ""), unusedArgsend

function p.jctint(frame) -- Import module function to work with passed arguments local getArgs = require('Module:Arguments').getArgs local args = getArgs(frame)

-- Remove parameters already used in the template definition if args.used_params then for param in mw.text.gsplit(args.used_params, ",") do args[param] = nil end args.used_params = nil end

local result, unusedArgs = p._jctint(args)

-- Check for overridden arguments local frameArgs = getArgs(frame,) local parentArgs = getArgs(frame,) for key,_ in pairs(frameArgs) do if parentArgs[key] then insert(unusedArgs, key) end end

-- Report unused arguments local msg if #unusedArgs > 0 then msg = format("" .. 'Module:Jctint/USA warning: Unused argument(s): %s', "U", concat(unusedArgs, ", ")) local page = mw.title.getCurrentTitle.prefixedText -- Get transcluding page's title msg = mw.ustring.gsub(msg, "%%page%%", page) end return result .. (msg or "")end

return p