Module:Interprovincial highway: Difference between revisions

Content deleted Content added
Module for the future Template:Interprovincial highway
 
Update error message
 
(10 intermediate revisions by the same user not shown)
Line 1:
require('strict')
 
local p = {}
local parser = require('Module:Road data/parser').parser
local getArgs = require('Module:Arguments').getArgs
local parserModuledata = requiremw.loadData('Module:RoadInterprovincial datahighway/parserdata')
local parser = parserModule.parser
 
-- Generate a link to a route
local function makeRoute(route, routeType, routeLoc, currProvince)
local out = ''
Line 15 ⟶ 17:
local shield = parser(parserArgs, 'shieldmain') or parser(parserArgs, 'shield') or ''
local label = (routeLoc ~= currProvince and (routeLoc .. ' ') or '') .. label
local label = .. (parser(parserArgs, 'name') or parser(parserArgs, 'abbr') or '')
label = (routeLoc ~= currProvince and (routeLoc .. ' ') or '') .. label
 
local link = parser(parserArgs, 'link')
local alt = label .. ' marker'
Line 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 makeNav(out
end
 
-- Generate the content for a prev/next navigation table cell
local function makeNav(prefix, label, currProvince, args)
local index = 1
local out = ''
local index = 1
repeat
local paramPrefix = prefix
local route = args[prefix .. index] or (index == 1 and args[prefix] or '')
)
local routeType = args[prefix .. index .. '_type'] or (index == 1 and args[prefix .. '_type'] or '')
while args[paramPrefix] and args[paramPrefix] ~= '' do
local routeLoc = args[prefix .. index .. '_province'] or (index == 1 and args[prefix .. '_province'] or '')
local route = args[paramPrefix]
local routeType = args[paramPrefix .. '_type']
local routeLoc = args[paramPrefix .. '_province']
if index ~= 1 then
Line 53 ⟶ 62:
index = index + 1
until paramPrefix not= args[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
local p = {}
local function getName(type)
return data.types[type] or require('Module:Error').error{'Unknown name'}
end
 
-- Generate highway rows (headers and content cells)
function p.routerows(frame)
return makeRoute(
local args = getArgs(frame)
frame.args[1],
local out = ''
frame.args.type,
 
frame.args.province,
returnlocal current = makeRoute(
frame.args.current_province or frame.args.province
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.navsupported(frame)
return makeNav(
local data = mw.loadData('Module:Interprovincial highway/data')
frame.args[1],
local post = 'Types retrieved from [[Module:Interprovincial highway/data]] ('
frame.args.label,
.. frame:expandTemplate{ title = 'edit', args = { 'Module:Interprovincial highway/data' } } .. ').'
frame.args.current_province,
 
getArgs(frame, { parentOnly = true })
local tableEl = mw.html.create('table'):addClass('wikitable')
)
local headerRow = tableEl:tag('tr')
headerRow:tag('th'):wikitext('Value')
headerRow:tag('th'):wikitext('Title')
 
for name, title in pairs(data.types) do
local row = tableEl:tag('tr')
row:tag('td'):tag('code'):wikitext(name)
row:tag('td'):wikitext("'''" .. title .. "'''")
end
 
return tostring(tableEl) .. post
end