Aller au contenu

Module:AhnentafelChart

De Wikiquestia
Version datée du 12 juin 2025 à 12:20 par Alakihel (discussion | contributions) (Page créée avec « local p = {} function p.main(frame) local args = frame:getParent().args local output = {} table.insert(output, '<div class="mw-ahnentafel-chart"><table class="wikitable" style="width:100%;">') table.insert(output, '<tr><th>N°</th><th>Ascendant</th></tr>') -- Récupération dynamique des identifiants local indices = {} for k, _ in pairs(args) do local base = tostring(k):match('^(%d+)-nom$') if base then table.insert(indices, tonumber(base)) end... »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)

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

local p = {}

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

	table.insert(output, '<div class="mw-ahnentafel-chart"><table class="wikitable" style="width:100%;">')
	table.insert(output, '<tr><th>N°</th><th>Ascendant</th></tr>')

	-- Récupération dynamique des identifiants
	local indices = {}
	for k, _ in pairs(args) do
		local base = tostring(k):match('^(%d+)-nom$')
		if base then
			table.insert(indices, tonumber(base))
		end
	end
	table.sort(indices)

	for _, i in ipairs(indices) do
		local nom = args[i .. '-nom'] or ''
		local image = args[i .. '-image'] or ''
		local dates = args[i .. '-dates'] or ''

		local bloc = {}
		table.insert(bloc, '<div style="text-align:center;">')

		if nom ~= '' then
			table.insert(bloc, '<div style="font-weight:bold; font-size:1.1em;">' .. nom .. '</div>')
		end

		if image ~= '' then
			table.insert(bloc, string.format('[[Fichier:%s|100px|center]]', image))
		end

		if dates ~= '' then
			table.insert(bloc, '<div style="font-size:0.9em; color:gray;">' .. dates .. '</div>')
		end

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

		table.insert(output, string.format('<tr><td>%d</td><td>%s</td></tr>', i, table.concat(bloc, '\n')))
	end

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

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

return p