Module:Historical affiliations

MyWikiBiz, Author Your Legacy — Wednesday September 28, 2022
Jump to navigationJump to search
local getArgs = require('Module:Arguments').getArgs
local p = {}

function image (frame, image)
	local file = nil
	if not image then
		return nil
	end
	local file = ''
	if string.match(image,"(.-)%.(.*)") then
		file = frame:expandTemplate{title = "flagicon image", args = { image } }
	elseif string.match(image,".-%s%(.-%)") then
		local country, var = string.match(image,"(.-)%s%((.-)%)")
		file = frame:expandTemplate{title = "flagdeco", args = { country, var } }
	else
		file = frame:expandTemplate{title = "flagdeco", args = { image } }
	end
	return file
end

function p.main (frame)
	local args = getArgs(frame)
	local out = ''
	local images = {}
	local countries = {}
	local i = 1
	while args['c' .. i] do
		images[i] = image(frame, args['i' .. i])
		countries[i] = args['c' .. i] .. (args['y' .. i] and ' (' .. args['y' .. i] .. ')' or '')
		i = i + 1
	end
	local hasimages = next(images)
	for i, country in ipairs(countries) do
		out = out .. '<tr>'
		out = out .. (images[i] and ('<td style="vertical-align:top;">' .. images[i] .. '</td>') or (hasimages and '<td></td>' or ''))
		out = out .. '<td style="width:100%;vertical-align:top;">' .. country .. '</td>'
		out = out .. '</tr>'
	end
	local html = '<table style="padding:5px;float:' .. (args.float or 'left') .. ';background-color:#B0C4DE;border:1px solid #aaa;width:20em;font-size:90%;">'
	html = html .. '<tr><th colspan="' .. (hasimages and 2 or 1) .. '" style="text-align:center;font-size:larger;font-weight:bold;">' .. (args.title and args.title or 'Historical affiliations') .. '</th></tr>'
	html = html .. out
	html = html .. '</table>'
	return html
end

return p