Jump to content

Module:Jctint

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Happy5214 (talk | contribs) at 07:13, 24 September 2013 (Adding first-level subdivisions). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

local format = mw.ustring.format
local HtmlBuilder = require "Module:HtmlBuilder"

local function locations(args, root)
	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 ''
	if sub1 ~= '' or sub1Special ~= '' then
		local sub1name = args.sub1name or ''
		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
	
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