Module:Infobox commune

De WikiPerche

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

local capiunto = require 'capiunto'

local p = {}

-- Renvoie la valeur nettoyée, ou nil si absente/vide
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

-- Ajoute une ligne seulement si la valeur existe ; renvoie toujours l'infobox
local function addRow(box, label, value)
	value = clean(value)
	if value then
		box:addRow(label, value)
	end
	return box
end

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

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

	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, "Nombre d'habitants", args.habitants)
	addRow(box, 'Gentilé', args.gentile)
	addRow(box, 'Site web', args.siteweb)

	box:addHeader('Géographie')
	addRow(box, 'Superficie', args.superficie)
	addRow(box, 'Densité de population', args.densite)
	addRow(box, 'Altitude', args.altitude)
	addRow(box, 'Bassin de vie', args.bassin)

	box:addHeader('Informations administratives')
	addRow(box, 'Maire', args.maire)
	addRow(box, 'Intercommunalité', args.cdc)
	addRow(box, 'Département', args.departement)
	addRow(box, 'Région', args.region)
	addRow(box, 'Code postal', args.codepostal)
	addRow(box, 'Code INSEE', args.codeinsee)

	return box
end

return p