Module:Jcttop/core
Appearance
This module implements {{jcttop/core}}.
local p = {}
local format = mw.ustring.format -- Local version of string formatting function
local HtmlBuilder = require "Module:HtmlBuilder" -- Import module to build HTML code
local getArgs = require('Module:Arguments').getArgs -- Import module function to work with passed arguments
local function hatnote(args)
return ''
end
local function header(args)
local row = HtmlBuilder.create().tag('table', {unclosed = true}).attr('class', 'plainrowheaders wikitable hlist').tag('tr')
local region_col = args.region_col
if region_col then
row.tag('th').attr('scope', 'col').wikitext(region_col)
end
local nosub1 = args.nosub1 == 'yes'
local indep_city = args.indep_city
if not(nosub1 or args.sub1 or indep_city) then
local tag = row.tag('th').attr('scope', 'col')
local sub1disp = args.sub1disp
if sub1disp then
tag.wikitext(sub1disp)
else
tag.wikitext(args.sub1name).wikitext(args.sub1_ref)
end
end
if not(args.sub2 or indep_city) then
local tag = row.tag('th').attr('scope', 'col')
local location_def = args.location_def or 'Location'
tag.wikitext(location_def).wikitext(args.sub2_ref)
end
local altunit = args.altunit
if altunit then
row.tag('th').attr('scope', 'col').wikitext(altunit).wikitext(args.altunit_ref)
else
local unit = args.length or args.unit
if unit ~= 'off' then
row.tag('th').attr('scope', 'col').wikitext(unit).wikitext(args.length_ref).done().tag('th').attr('scope', 'col').wikitext(args.unit2)
end
end
local exit = args[1]
if exit == 'old' then
local old_def = args.old_def or 'Old exit'
row.tag('th').attr('scope', 'col').wikitext(old_def).wikitext(args.old_ref)
local exit_def = args.exit_def or 'New exit'
row.tag('th').attr('scope', 'col').wikitext(exit_def).wikitext(args.exit_ref)
elseif exit == 'exit' then
local exit_def = args.exit_def or 'Exit'
row.tag('th').attr('scope', 'col').wikitext(exit_def).wikitext(args.exit_ref)
end
if args[2] == 'name' then
local name_def = args.name_def or 'Name'
row.tag('th').attr('scope', 'col').wikitext(name_def).wikitext(args.name_ref)
end
local dest_def = args.dest_def or 'Destinations'
row.tag('th').attr('scope', 'col').wikitext(dest_def).wikitext(args.dest_ref)
local notes_def = args.notes_def or 'Notes'
row.tag('th').attr('scope', 'col').wikitext(notes_def).wikitext(args.notes_ref)
return tostring(row.allDone())
end
function p._jcttop(args)
-- This function calls two other functions to generate a hatnote and header row.
-- This function is accessible from other Lua modules.
return hatnote(args) .. header(args)
end
function p.jcttop(frame)
-- Entry function for {{jcttop/core}}
local args = getArgs(frame) -- Gather passed arguments into easy-to-use table.
return p._jcttop(args) -- Simply call another function with those arguments to actually create the header.
end
return p