Aller au contenu

Module:AhnentafelChart

De Wikiquestia

La documentation pour ce module peut être créée à Module:AhnentafelChart/doc

local p = {}

local function renderCell(nom, image, dates)
	local html = {}
	table.insert(html, '<div style="text-align:center;">')
	if nom and nom ~= '' then
		table.insert(html, '<div style="font-weight:bold;">' .. nom .. '</div>')
	end
	if image and image ~= '' then
		table.insert(html, string.format('[[Fichier:%s|80px|center]]', image))
	end
	if dates and dates ~= '' then
		table.insert(html, '<div style="font-size:0.85em; color:gray;">' .. dates .. '</div>')
	end
	table.insert(html, '</div>')
	return table.concat(html, '\n')
end

function p.main(frame)
	local args = frame:getParent().args
	local out = {}

	table.insert(out, '<div class="mw-ahnentafel-tree"><table style="width:100%; text-align:center; border-spacing:10px;">')

	-- Génération 3 : 4 à 7
	table.insert(out, '<tr>')
	for i = 4, 7 do
		local nom = args[i .. '-nom'] or ''
		local img = args[i .. '-image'] or ''
		local dates = args[i .. '-dates'] or ''
		table.insert(out, '<td style="width:25%;">' .. renderCell(nom, img, dates) .. '</td>')
	end
	table.insert(out, '</tr>')

	-- Génération 2 : 2 et 3
	table.insert(out, '<tr>')
	for i = 2, 3 do
		local nom = args[i .. '-nom'] or ''
		local img = args[i .. '-image'] or ''
		local dates = args[i .. '-dates'] or ''
		table.insert(out, '<td colspan="2">' .. renderCell(nom, img, dates) .. '</td>')
	end
	table.insert(out, '</tr>')

	-- Génération 1 : 1
	local nom = args['1-nom'] or ''
	local img = args['1-image'] or ''
	local dates = args['1-dates'] or ''
	table.insert(out, '<tr><td colspan="4">' .. renderCell(nom, img, dates) .. '</td></tr>')

	table.insert(out, '</table></div>')

	return table.concat(out, '\n')
end

return p