Module:Interprovincial highway: Difference between revisions

Content deleted Content added
Bold supported table
Update error message
 
(8 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 24 ⟶ 26:
end
if shield and shield ~= '' then
out = out .. string.format('[[File:%s|15px|alt=%s]]', shield, alt) .. ' '
end
if not link or link == '' then
out = out .. ' ' .. label
else
out = out .. ' ' .. string.format('[[%s|%s]]', link, label)
end
return "'''" ..if out ..~= "'''" then
out = "'''" .. out .. "'''"
end
)
return makeRoute(out
end
 
-- Generate the content for a prev/next navigation table cell
function p.route(frame)
local function makeNav(prefix, label, currProvince, args)
return makeRoute(
frame.args[1],
frame.args.type,
frame.args.province,
frame.args.current_province or frame.args.province
)
end
 
function p.nav(frame)
local prefix = frame.args[1]
local label = frame.args.label
local currProvince = frame.args.current_province
local templateArgs = frame:getParent().args
 
local index = 1
local out = ''
local index = 1
repeat
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 70 ⟶ 62:
index = index + 1
until paramPrefix not= templateArgs[prefix .. index]
end
if out == '' then
out = "'''Terminus'''"
end
return label .. ' ' .. (index - 1 > 1 and 'routes' or 'route') .. '<br>' .. out
end
 
-- Generate the name for a highway type
function p.type(frame)
local function getName(type)
local data = mw.loadData('Module:Sandbox/BrandonXLF/Module:Interprovincial highway/data')
return data.types[frametype] or require('Module:Error').args[1]]error{'Unknown name'}
end
 
-- Generate highway rows (headers and content cells)
function p.routerows(frame)
local prefixargs = getArgs(frame.args[1])
local out = ''
 
local current = makeRoute(
frame.args.typecurr,
args.curr_type,
args.curr_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
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' } } .. ').'