Module:Jctrdt/sandbox: Difference between revisions
Appearance
Content deleted Content added
BrandonXLF (talk | contribs) No edit summary |
BrandonXLF (talk | contribs) displayModule |
||
Line 16: | Line 16: | ||
local parser = parserModule.parser |
local parser = parserModule.parser |
||
local util = require("Module:Road data/util") |
local util = require("Module:Road data/util") |
||
local |
local displayModule = require("Module:Sandbox/BrandonXLF/4") |
||
local function stateName(args) |
local function stateName(args) |
||
Line 33: | Line 33: | ||
link = route.route |
link = route.route |
||
else |
else |
||
link = |
link = displayModule.link(route) |
||
end |
end |
||
Line 110: | Line 110: | ||
for num,route in ipairs(routes) do |
for num,route in ipairs(routes) do |
||
if not (args.noshield or route.noshield) then |
if not (args.noshield or route.noshield) then |
||
local shield = |
local shield = displayModule.shield(route, nil, 'rdt') |
||
insert(shields, shield) |
insert(shields, shield) |
||
end |
end |
Revision as of 08:01, 22 August 2024
![]() | This is the module sandbox page for Module:Jctrdt (diff). |
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
Implements {{Jctrdt}}
local p = {}
-- Change to "" upon deployment.
local moduleSuffix = ""
local parserModuleName = "Module:Road data/parser" .. moduleSuffix
local statenameModuleName = "Module:Jct/statename" .. moduleSuffix -- TODO transition
local cityModuleName = "Module:Jct/city" .. moduleSuffix
local concat = table.concat
local insert = table.insert
local format = mw.ustring.format
local trim = mw.text.trim
local parserModule = require(parserModuleName)
local parser = parserModule.parser
local util = require("Module:Road data/util")
local displayModule = require("Module:Sandbox/BrandonXLF/4")
local function stateName(args)
-- TODO transition
local data = mw.loadData(statenameModuleName)
local abbr = args.state or args.province
local countryData = data[args.country]
return countryData and countryData[abbr]
end
-- Links/abbreviations
local function routeText(route, frame)
local link
local type = route.type
if not type or type == '' then
link = route.route
else
link = displayModule.link(route)
end
local dir = route.dir and ' ' .. string.lower(route.dir) or ''
local routeText = link .. dir
local name = route.name
if name and name ~= '' then
local mainText = routeText
local parenText = name
return frame:expandTemplate{ title = 'BSsplit', args = {mainText, parenText, align = 'left', valign = 'middle' } }
else
return routeText
end
end
local function parseArgs(args)
local state = args.state or args.province or ''
args.state = state
local country
if args.country and args.country ~= '' then
country = string.upper(args.country)
else
local countryModule = mw.loadData("Module:Road data/countrymask")
country = countryModule[state] or 'UNK'
end
args.country = country
local params = {'denom', 'county', 'township', 'dab', 'nolink', 'noshield', 'to', 'dir', 'name'}
local routes = {}
local routeCount = 1
local seenTo = false
while true do
local routeType = args[routeCount * 2 - 1]
if not routeType then break end
local route = {type = routeType, route = args[routeCount * 2]}
for _,v in pairs(params) do
route[v] = args[v .. routeCount]
end
route.country = country
route.state = state
-- Set the first .to to true.
-- Set all following .to to ''.
if seenTo then
if route.to then
-- Report duplicate to flag.
route.toerror = true
end
route.to = ''
elseif route.to then
route.to = true
seenTo = true
end
route.rdt = args.rdt
insert(routes, route)
routeCount = routeCount + 1
end
return routes
end
local function prefix(to, num)
if to and to ~= '' then
return num == 1 and 'To ' or ' to '
end
return num == 1 and '' or ' / '
end
function p._jctrdt(args, frame)
local routes = parseArgs(args)
local shields = {}
local links = {}
frame = frame or mw.getCurrentFrame()
for num,route in ipairs(routes) do
if not (args.noshield or route.noshield) then
local shield = displayModule.shield(route, nil, 'rdt')
insert(shields, shield)
end
local prefix = prefix(route.to, num)
if prefix ~= '' then insert(links, prefix) end
insert(links, routeText(route, frame))
end
local graphics = concat(shields) .. ' '
local linkText = concat(links)
local cities = ''
if args.city1 or args.location1 then
local citiesPrefix
if args.citiesprefix then
citiesPrefix = args.citiesprefix ~= '' and format(" %s ", args.citiesprefix) or ''
else
citiesPrefix = ' '
end
local cityModule = require(cityModuleName)
cities = citiesPrefix .. cityModule.city(args)
end
return graphics .. linkText .. cities
end
function p.jctrdt(frame)
-- Import module function to work with passed arguments
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame, {removeBlanks = false})
return p._jctrdt(args, frame)
end
return p