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 09:35, 23 September 2013 (Adding regions and independent cities. Module is not currently usable.). 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 primaryTopic = 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 primaryTopic 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
		indepCityCell.tag('br', {selfClosing = true})
		if sub1note ~= '' then
			indepCityCell.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