Module:Jcttop/core/sandbox
Appearance
![]() | This is the module sandbox page for Module:Jcttop/core (diff). See also the companion subpage for test cases (run). |
This module implements {{jcttop/core}}.
local p = {}
-- Shorthands for library functions
local format = mw.ustring.format
local concat = table.concat
local insert = table.insert
local roadDataModule = require("Module:Road data")
local needSub1Col = true
local needSub2Col = true
local function location(args)
local locns = roadDataModule.locations(args, true)
if locns.indep_city then
needSub1Col = false
needSub2Col = false
return locns.indep_city
end
if locns.sub1 then needSub1Col = false end
if locns.sub2 then
needSub2Col = false
if locns.sub1 then
return format("%s, %s", locns.sub2, locns.sub1)
end
return locns.sub2
end
return locns.sub1
end
local function hatnote(args)
local isFormer = args.former == "yes"
local text = {}
if args.region_note then
insert(text, args.region_note)
end
local hatnoteArg = args.hatnote
if hatnoteArg then
if hatnoteArg ~= "off" then
insert(text, hatnoteArg)
end
else
local location = location(args)
if location then
local verb = isFormer and 'was' or 'is'
insert(text, format("The entire %s %s in %s.%s%s",
args.type or 'route', verb, location,
not needSub1Col and args.sub1_ref or "",
not needSub2Col and args.sub2_ref or ""))
end
end
if args.unnum == 'yes' then
local verb = isFormer and 'were' or 'are'
insert(text, format("All exits %s unnumbered.", verb))
end
return concat(text, " ")
end
local function header(args)
local row = mw.html.create('tr')
local region_col = args.region_col
if region_col then
row:tag('th'):attr('scope', 'col')
:wikitext(mw.language.getContentLanguage():ucfirst(region_col))
end
if needSub1Col and not (args.nosub1 and args.nosub1 == "yes") then
row:tag('th'):attr('scope', 'col')
:wikitext(args.sub1disp or args.sub1name, args.sub1_ref)
end
if needSub2Col then
row:tag('th'):attr('scope', 'col')
:wikitext(args.location_def or 'Location', args.sub2_ref)
end
local altunit = args.altunit
if altunit then
row:tag('th'):attr('scope', 'col')
:wikitext(altunit, args.altunit_ref)
else
local unit = args.length or args.unit
if unit ~= 'off' then
row:tag('th'):attr('scope', 'col')
:wikitext(unit, args.length_ref)
row:tag('th'):attr('scope', 'col')
:wikitext(args.unit2)
end
end
local exit = args[1]
if exit == 'old' then
row:tag('th'):attr('scope', 'col')
:wikitext(args.old_def or 'Old exit', args.old_ref)
row:tag('th'):attr('scope', 'col')
:wikitext(args.exit_def or 'New exit', args.exit_ref)
elseif exit == 'exit' then
row:tag('th'):attr('scope', 'col')
:wikitext(args.exit_def or 'Exit', args.exit_ref)
end
if args[2] == 'name' then
row:tag('th'):attr('scope', 'col')
:wikitext(args.name_def or 'Name', args.name_ref)
end
row:tag('th'):attr('scope', 'col')
:wikitext(args.dest_def or 'Destinations', args.dest_ref)
row:tag('th'):attr('scope', 'col')
:wikitext(args.notes_def or 'Notes', args.notes_ref)
return '\n{| class="plainrowheaders wikitable hlist"\n' .. tostring(row)
end
---
-- Generate a hatnote and the header row for a junction-list table.
-- Accessible from other Lua modules.
function p._jcttop(args)
return hatnote(args) .. header(args)
end
--- Entry function for {{jcttop/core}}
function p.jcttop(frame)
-- Import module function to work with passed arguments
local getArgs = require('Module:Arguments').getArgs
-- Gather passed arguments into easy-to-use table
local args = getArgs(frame)
return p._jcttop(args)
end
return p