Module:Jctint
Appearance
![]() | This Lua module is used on 15,000+ pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
This module implements the {{jctint/core}} template. Please see the template page for usage instructions.
Usage
From wikitext
{{#invoke:Jctint|jctint}}
From Lua
local jctintCoreModule = require("Module:Jctint")
jctintCoreModule._jctint(args)
Tracking categories
local p = {}
local format = mw.ustring.format
local HtmlBuilder = require "Module:HtmlBuilder"
local function locations(args, root)
local areas = {village = "Village", city = "City", town = "Town", community = "Community", CDP = "Community", hamlet = "Hamlet", ["unorganized territory"] = "Unorganized Territory"}
local notPrimaryTopic = args.primary_topic == 'no'
-- Regions
local regionSpan = args.regionspan or ''
local region = args.region
if regionSpan ~= '' then
local regionCell = root.tag('td').attr('rowspan', regionSpan)
local regionSpecial = args.region_special or ''
local regionContent = regionSpecial ~= '' and regionSpecial or ('[[' .. region .. ']]')
regionCell.wikitext(regionContent)
end
-- Independent Cities
local indepCity = args.indep_city or ''
local indepCitySpecial = args.indep_city_special or ''
local sub1note = args.sub1_note or ''
local sub2span = args.sub2span or '1'
if indepCity ~= '' or indepCitySpecial ~= '' then
local indepCityCell = root.tag('td').attr('colspan', '2').attr('rowspan', sub2span)
local align = args.indep_city_align or ''
align = align ~= '' and align or 'left'
indepCityCell.css('text-align', align)
if indepCitySpecial ~= '' then
indepCityCell.wikitext(indepCitySpecial)
elseif notPrimaryTopic then
local text = format('[[Independent city|City]] of [[%s, %s|%s]]', indepCity, region, indepCity)
indepCityCell.wikitext(text)
else
local text = format('[[Independent city|City]] of [[%s]]', indepCity)
indepCityCell.wikitext(text)
end
if sub1note ~= '' then
indepCityCell.tag('br', {selfClosing = true})
indepCityCell.tag('small').wikitext(sub1note)
end
end
-- First-level Subdivisions
local sub1 = args.sub1 or ''
local sub1Special = args.sub1_special or ''
local sub1name = args.sub1name or ''
if sub1 ~= '' or sub1Special ~= '' then
local sub1span = args.sub1span or '1'
local sub1Cell = root.tag('td').attr('rowspan', sub1span)
if sub1Special ~= '' then
sub1Cell.wikitext(sub1Special)
elseif notPrimaryTopic then
local text = format('[[%s %s, %s|%s]]', sub1, sub1name, region, sub1)
sub1Cell.wikitext(text)
else
local text = '[[' .. sub1
if sub1name ~= '' then
text = text .. format(' %s|%s', sub1name, sub1)
end
sub1Cell.wikitext(text .. ']]')
end
if sub1note ~= '' then
sub1Cell.tag('br', {selfClosing = true})
sub1Cell.tag('small').wikitext(sub1note)
end
end
-- Second-level Subdivisions
local sub2 = args.sub2 or ''
local sub2Special = args.sub2_special or ''
if sub2 == 'none' then
root.tag('td').wikitext(" ")
elseif sub2Special ~= '' then
root.tag('td').attr('rowspan', sub2span).wikitext(sub2Special)
elseif sub2 ~= '' then
local sub2Cell = root.tag('td').attr('rowspan', sub2span)
if not notPrimaryTopic then
sub2Cell.wikitext('[[' .. sub2 .. ']]')
else
local text = {'[[', sub2}
local area = args.area or ''
local insert = table.insert
if area ~= '' then
insert(text, format(' (%s)', area))
end
insert(text, ", ")
local sub1dab = args.sub1dab or ''
if sub1dab ~= '' then
insert(text, format('%s %s, ', sub1dab, sub1name))
end
insert(text, region .. '|')
if area ~= '' then
local linktext = areas[area]
insert(text, linktext .. ' of ')
end
insert(text, sub2 .. ']]')
sub2Cell.wikitext(table.concat(text))
end
end
end
function p.locations(args)
--[[function p.locations(frame)
local pframe = frame:getParent()
local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template]]
local root = HtmlBuilder.create()
local unitary = args.unitary or ''
if unitary ~= '' then
local tag = root.tag('td').attr('colspan', '3').wikitext(unitary)
local align = args.unitary_align or ''
align = align ~= '' and align or 'left'
tag.css('text-align', align)
else
locations(args, root)
end
return tostring(root)
end
return p