Module:Interprovincial highway/sandbox explained

require('strict')

local p = local parser = require('Module:Road data/parser').parserlocal getArgs = require('Module:Arguments').getArgslocal data = mw.loadData('Module:Interprovincial highway/data')

-- Generate a link to a routelocal function makeRoute(route, routeType, routeLoc, currProvince) local out = local parserArgs = local shield = parser(parserArgs, 'shieldmain') or parser(parserArgs, 'shield') or local label = (routeLoc ~= currProvince and (routeLoc .. ' ') or ) .. (parser(parserArgs, 'name') or parser(parserArgs, 'abbr') or ) local link = parser(parserArgs, 'link') local alt = label .. ' marker' if type(shield)

'table' then shield = shield[1] end if shield and shield ~= then out = out .. string.format('', shield, alt) .. ' ' end if not link or link

then out = out .. label else out = out .. string.format('%s', link, label) end if out ~= then out = "" .. out .. "" end return outend

-- Generate the content for a prev/next navigation table celllocal function makeNav(prefix, label, currProvince, args) local out = local index = 1 local paramPrefix = prefix while args[paramPrefix] and args[paramPrefix] ~= do local route = args[paramPrefix] local routeType = args[paramPrefix .. '_type'] local routeLoc = args[paramPrefix .. '_province'] if index ~= 1 then out = out .. '


' end out = out .. makeRoute(route, routeType, routeLoc, currProvince) index = index + 1 paramPrefix = prefix .. index end if out

then out = "Terminus" end return label .. ' ' .. (index - 1 > 1 and 'routes' or 'route') .. '
' .. outend

-- Generate the name for a highway typelocal function getName(type) return data.types[type] or require('Module:Error').errorend

-- Generate highway rows (headers and content cells)function p.rows(frame) local args = getArgs(frame) local out =

local current = makeRoute(args.curr, args.curr_type, args.curr_province, args.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 outend

-- Show the supported types in a tablefunction p.supported(frame) local data = mw.loadData('Module:Interprovincial highway/data') local post = 'Types retrieved from (' .. frame:expandTemplate .. ').'

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) .. postend

return p