Aller au contenu

« Module:AhnentafelChart » : différence entre les versions

De Wikiquestia
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... »
 
Aucun résumé des modifications
Ligne 1 : Ligne 1 :
local p = {}
local p = {}
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)
function p.main(frame)
local args = frame:getParent().args
local args = frame:getParent().args
local output = {}
local out = {}


table.insert(output, '<div class="mw-ahnentafel-chart"><table class="wikitable" style="width:100%;">')
table.insert(out, '<div class="mw-ahnentafel-tree"><table style="width:100%; text-align:center; border-spacing:10px;">')
table.insert(output, '<tr><th>N°</th><th>Ascendant</th></tr>')


-- Récupération dynamique des identifiants
-- Ligne 3e génération (4 à 7)
local indices = {}
table.insert(out, '<tr>')
for k, _ in pairs(args) do
for i = 4, 7 do
local base = tostring(k):match('^(%d+)-nom$')
local nom = args[i .. '-nom'] or ''
if base then
local img = args[i .. '-image'] or ''
table.insert(indices, tonumber(base))
local dates = args[i .. '-dates'] or ''
end
table.insert(out, '<td style="width:25%;">' .. renderCell(nom, img, dates) .. '</td>')
end
end
table.sort(indices)
table.insert(out, '</tr>')


for _, i in ipairs(indices) do
-- Ligne 2e génération (2 et 3)
table.insert(out, '<tr>')
for i = 2, 3 do
local nom = args[i .. '-nom'] or ''
local nom = args[i .. '-nom'] or ''
local image = args[i .. '-image'] or ''
local img = args[i .. '-image'] or ''
local dates = args[i .. '-dates'] or ''
local dates = args[i .. '-dates'] or ''
 
table.insert(out, '<td colspan="2">' .. renderCell(nom, img, dates) .. '</td>')
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
end
table.insert(out, '</tr>')


table.insert(output, '</table></div>')
-- Ligne 1re génération (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>')


return table.concat(output, '\n')
table.insert(out, '</table></div>')
return table.concat(out, '\n')
end
end


return p
return p

Version du 12 juin 2025 à 14:08

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

local p = {}

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;">')

	-- Ligne 3e génération (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>')

	-- Ligne 2e génération (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>')

	-- Ligne 1re génération (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