Module:Interprovincial highway: Difference between revisions

Content deleted Content added
Still show label for termini
Update error message
 
(3 intermediate revisions by the same user not shown)
Line 2:
 
local p = {}
local parserModuleparser = require('Module:Road data/parser').parser
local getArgs = require('Module:Arguments').getArgs
local parser = parserModule.parser
local data = mw.loadData('Module:Sandbox/BrandonXLF/Module:Interprovincial highway/data')
 
-- Generate a link to a route
local function makeRoute(route, routeType, routeLoc, currProvince)
local out = ''
Line 41 ⟶ 43:
end
 
-- Generate the content for a singleprev/next navigation routetable link.cell
local function makeNav(prefix, label, currProvince, args)
--
-- Current frame arguments:
-- 1 - The route number.
-- type - The route type.
-- province - The route province.
-- curr_province - The current province. Defaults to <province>.
-- Parent frame arguments: None
function p.route(frame)
return makeRoute(
frame.args[1],
frame.args.type,
frame.args.province,
frame.args.curr_province or frame.args.province
)
end
 
-- Generate prev/next navigation links.
--
-- Current frame arguments:
-- 1 - The prefix of the parent frame parameters to process.
-- label - The label for the output. Shown as "<label> route(s)".
-- curr_province - The current province.
-- Parent frame arguments:
-- <prefix><number?> - The route number.
-- <prefix><number?>_type - The route type.
-- <prefix><number?>_type - The route province.
function p.nav(frame)
local prefix = frame.args[1]
local label = frame.args.label
local currProvince = frame.args.curr_province
local templateArgs = frame:getParent().args
 
local index = 1
local out = ''
local index = 1
while templateArgs[prefix .. index] or (index == 1 and templateArgs[prefix ]) do
local routeparamPrefix = templateArgs[prefix .. index]
or (index == 1 and templateArgs[prefix] or '')
while args[paramPrefix] and args[paramPrefix] ~= '' do
 
local routeTyperoute = templateArgsargs[prefix .. index .. '_type'paramPrefix]
orlocal (indexrouteType == 1 and templateArgsargs[prefixparamPrefix .. '_type'] or '')
local routeLoc = templateArgsargs[prefix .. indexparamPrefix .. '_province']
 
local routeLoc = templateArgs[prefix .. index .. '_province']
or (index == 1 and templateArgs[prefix .. '_province'] or '')
if index ~= 1 then
Line 94 ⟶ 62:
index = index + 1
paramPrefix = prefix .. index
end
Line 103 ⟶ 72:
end
 
-- DisplayGenerate titlethe name for thea givenhighway type
local function getName(type)
--
return data.types[frame.args[1]type] or require('Module:Error').error{'Unknown |type=name'}
-- Current frame arguments:
end
-- 1 - The type to return the title for
 
-- Parent frame arguments: None
-- Generate highway rows (headers and content cells)
function p.type(frame)
function p.routerows(frame)
local data = mw.loadData('Module:Sandbox/BrandonXLF/Module:Interprovincial highway/data')
local prefixargs = getArgs(frame.args[1])
return data.types[frame.args[1]] or require('Module:Error').error{'Unknown |type='}
local out = ''
 
returnlocal current = makeRoute(
frame.args.typecurr,
args.curr_type,
frame.args.curr_province or frame.args.province,
frameargs.curr_province or args.province,
)
local index = 1
local paramPrefix = ''
repeat
out = out .. '|-\n'
out = out .. '! colspan=3 | ' .. getName(args[paramPrefix .. 'name']) .. '\n'
out = out .. '|- style="text-align: center;"' .. '\n'
out = out .. '| style="width: 30%;" | ' .. makeNav(paramPrefix .. 'prev', 'Previous', args.curr_province, args) .. '\n'
out = out .. '| style="width: 30%;" | ' .. current .. '\n'
out = out .. '| style="width: 30%;" | ' .. makeNav(paramPrefix .. 'next', 'Next', args.curr_province, args) .. '\n'
index = index + 1
paramPrefix = 'hwy' .. index .. '_'
until (not args[paramPrefix .. 'name']) or args[paramPrefix .. 'name'] == ''
return out
end
 
-- Show the supported types in a table.
--
-- Current frame arguments: None
-- Parent frame arguments: None
function p.supported(frame)
local data = mw.loadData('Module:Sandbox/BrandonXLF/Module:Interprovincial highway/data')
local post = 'Types retrieved from [[Module:Interprovincial highway/data]] ('
.. frame:expandTemplate{ title = 'edit', args = { 'Module:Interprovincial highway/data' } } .. ').'