Module:Infobox personnage

De WikiPerche
Version datée du 8 octobre 2026 à 15:44 par Admin (discussion | contributions)
(diff) ← Version précédente | Version actuelle (diff) | Version suivante → (diff)

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

local capiunto = require 'capiunto'

local p = {}

local function clean(v)
	if v == nil then return nil end
	v = mw.text.trim(tostring(v))
	if v == '' then return nil end
	return v
end

local function addRow(box, label, value)
	value = clean(value)
	if value then
		box:addRow(label, value)
	end
	return box
end

local function addSection(box, title, rows)
	local hasContent = false
	for _, r in ipairs(rows) do
		if clean(r[2]) then
			hasContent = true
			break
		end
	end
	if not hasContent then
		return box
	end

	box:addHeader(title)
	for _, r in ipairs(rows) do
		addRow(box, r[1], r[2])
	end
	return box
end

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

	local headerStyle = 'background-color:' .. (clean(args.headerstyle) or '#E3C234') .. ';'
	local titleStyle  = 'background-color:' .. (clean(args.titlestyle) or '#E3C234') .. ';'

	local box = capiunto.create{
		title = clean(args.title),
		titleStyle = titleStyle,
		headerStyle = headerStyle,
	}

	if clean(args.image) then
		box:addImage(args.image, clean(args.caption))
	end

	addRow(box, 'Nom complet', args.nomcomplet)
	addRow(box, 'Naissance', args.naissance)
	addRow(box, 'Décès', args.deces)

	addSection(box, 'Métier & vocations', {
		{ 'Profession(s)', args.metiers },
		{ 'Mandat(s)', args.mandats },
	})

	return box
end

return p