« Module:Infobox monument » : différence entre les versions

De WikiPerche
Page créée avec « local capiunto = require 'capiunto' local p = {} function p.main(frame) local args = frame:getParent().args local headerStyle if args.headerstyle and args.headerstyle ~= '' then headerStyle = string.format('background-color:%s;', args.headerstyle) else headerStyle = 'background-color:maroon;' end local retval = capiunto.create( { title = args.title, headerStyle = headerStyle, } ) :addImage( args.image, args.caption ) :addRow( 'Constructi... »
 
Aucun résumé des modifications
 
(14 versions intermédiaires par le même utilisateur non affichées)
Ligne 2 : Ligne 2 :


local p = {}
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)
function p.main(frame)
local args = frame:getParent().args
local args = frame:getParent().args
local headerStyle
 
if args.headerstyle and args.headerstyle ~= '' then
local headerStyle = 'background-color:' .. (clean(args.headerstyle) or '#8a6b23') .. ';'
headerStyle = string.format('background-color:%s;', args.headerstyle)
local titleStyle  = 'background-color:' .. (clean(args.titlestyle) or '#8a6b23') .. ';'
else
 
headerStyle = 'background-color:maroon;'
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
end
local retval = capiunto.create( {
title = args.title,
headerStyle = headerStyle,
} )
    :addImage( args.image, args.caption )
    :addRow( 'Construction', args.construction)
    :addRow( 'Propriété', args.propriete)
    :addHeader( 'Classement ou inscription au titre des monuments historiques' )
:addRow( 'Classé', args.mhclasse)
:addRow( 'Inscrit', args.mhinscrit)
    :addRow( 'Inscrit', args.mhobjet)


return retval
addRow(box, 'Construction', args.construction)
addRow(box, 'Destination initiale', args.destination)
addRow(box, 'Visite possible', args.visitable)
addRow(box, 'Propriété', args.propriete)
 
addSection(box, 'Localisation', {
{ 'Commune', args.commune },
})
 
addSection(box, 'Protection au titre des Monuments Historiques', {
{ 'Classé', args.mhclasse },
{ 'Inscrit', args.mhinscrit },
        { 'Patrimonialité', args.patrimonialite },
{ 'Objet(s) de la protection', args.mhobjet },
})
 
return box
end
end


return p
return p

Dernière version du 8 octobre 2026 à 20:17

La documentation pour ce module peut être créée à Module:Infobox monument/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 '#8a6b23') .. ';'
	local titleStyle  = 'background-color:' .. (clean(args.titlestyle) or '#8a6b23') .. ';'

	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, 'Construction', args.construction)
	addRow(box, 'Destination initiale', args.destination)
	addRow(box, 'Visite possible', args.visitable)
	addRow(box, 'Propriété', args.propriete)

	addSection(box, 'Localisation', {
		{ 'Commune', args.commune },
	})

	addSection(box, 'Protection au titre des Monuments Historiques', {
		{ 'Classé', args.mhclasse },
		{ 'Inscrit', args.mhinscrit },
        { 'Patrimonialité', args.patrimonialite },
		{ 'Objet(s) de la protection', args.mhobjet },
	})

	return box
end

return p