« Module:Infobox coursdeau » : différence entre les versions
De WikiPerche
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 3 : | Ligne 3 : | ||
local p = {} | local p = {} | ||
local function clean(v) | local function clean(v) | ||
if v == nil then return nil end | if v == nil then return nil end | ||
| Ligne 11 : | Ligne 10 : | ||
end | end | ||
local function addRow(box, label, value) | local function addRow(box, label, value) | ||
value = clean(value) | value = clean(value) | ||
if value then | if value then | ||
box:addRow(label, value) | 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 | end | ||
return box | return box | ||
| Ligne 40 : | Ligne 57 : | ||
addRow(box, 'Communes traversées', args.communestraversees) | addRow(box, 'Communes traversées', args.communestraversees) | ||
box | addSection(box, 'Hydrographie', { | ||
{ 'Source', args.source }, | |||
{ '· Localisation', args.localisationsource }, | |||
{ '· Altitude', args.altitudesource }, | |||
{ 'Confluence', args.confluence }, | |||
{ '· Localisation', args.pointdeconfluence }, | |||
{ 'Bassin collecteur', args.bassincollecteur }, | |||
}) | |||
return box | return box | ||
Version du 8 octobre 2026 à 15:43
La documentation pour ce module peut être créée à Module:Infobox coursdeau/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 'lightskyblue') .. ';'
local titleStyle = 'background-color:' .. (clean(args.titlestyle) or 'lightskyblue') .. ';'
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, 'Code SANDRE', args.codesandre)
addRow(box, 'Longueur', args.longueur)
addRow(box, 'Communes traversées', args.communestraversees)
addSection(box, 'Hydrographie', {
{ 'Source', args.source },
{ '· Localisation', args.localisationsource },
{ '· Altitude', args.altitudesource },
{ 'Confluence', args.confluence },
{ '· Localisation', args.pointdeconfluence },
{ 'Bassin collecteur', args.bassincollecteur },
})
return box
end
return p
