« Module:Infobox coursdeau » : différence entre les versions
De WikiPerche
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 18 : | Ligne 18 : | ||
end | end | ||
-- rows = { {'Label', valeur}, {'· Sous-label', valeur, true}, ... } | |||
-- Une ligne marquée true (3e élément) est une sous-ligne : elle n'est | |||
-- affichée que si la dernière ligne parente (sans true) est renseignée. | |||
local function addSection(box, title, rows) | local function addSection(box, title, rows) | ||
local | local visible = {} | ||
local parentShown = false | |||
for _, r in ipairs(rows) do | for _, r in ipairs(rows) do | ||
local label, value, isSub = r[1], clean(r[2]), r[3] | |||
if isSub then | |||
if value and parentShown then | |||
table.insert(visible, { label, value }) | |||
end | |||
else | |||
parentShown = value ~= nil | |||
if value then | |||
table.insert(visible, { label, value }) | |||
end | |||
end | end | ||
end | end | ||
if | |||
if #visible == 0 then | |||
return box | return box | ||
end | end | ||
box:addHeader(title) | box:addHeader(title) | ||
for _, r in ipairs( | for _, r in ipairs(visible) do | ||
addRow( | box:addRow(r[1], r[2]) | ||
end | end | ||
return box | return box | ||
| Ligne 59 : | Ligne 72 : | ||
addSection(box, 'Hydrographie', { | addSection(box, 'Hydrographie', { | ||
{ 'Source', args.source }, | { 'Source', args.source }, | ||
{ '· Localisation', args.localisationsource }, | { '· Localisation', args.localisationsource, true }, | ||
{ '· Altitude', args.altitudesource }, | { '· Altitude', args.altitudesource, true }, | ||
{ 'Confluence', args.confluence }, | { 'Confluence', args.confluence }, | ||
{ '· Localisation', args.pointdeconfluence }, | { '· Localisation', args.pointdeconfluence, true }, | ||
{ 'Bassin collecteur', args.bassincollecteur }, | { 'Bassin collecteur', args.bassincollecteur }, | ||
}) | }) | ||
Dernière version du 8 octobre 2026 à 15:56
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
-- rows = { {'Label', valeur}, {'· Sous-label', valeur, true}, ... }
-- Une ligne marquée true (3e élément) est une sous-ligne : elle n'est
-- affichée que si la dernière ligne parente (sans true) est renseignée.
local function addSection(box, title, rows)
local visible = {}
local parentShown = false
for _, r in ipairs(rows) do
local label, value, isSub = r[1], clean(r[2]), r[3]
if isSub then
if value and parentShown then
table.insert(visible, { label, value })
end
else
parentShown = value ~= nil
if value then
table.insert(visible, { label, value })
end
end
end
if #visible == 0 then
return box
end
box:addHeader(title)
for _, r in ipairs(visible) do
box:addRow(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, true },
{ '· Altitude', args.altitudesource, true },
{ 'Confluence', args.confluence },
{ '· Localisation', args.pointdeconfluence, true },
{ 'Bassin collecteur', args.bassincollecteur },
})
return box
end
return p
