« Module:Fonctions » : différence entre les versions
Apparence
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 1 : | Ligne 1 : | ||
local p = {} | local p = {} | ||
local function genererBloc(args, | -- Génère un bloc HTML unique pour une fonction | ||
local titre = args["Titre" .. | local function genererBloc(args, index, frame) | ||
local mandat = args["Mandat" .. | local titre = args["Titre" .. index] | ||
local predecesseur = args["Prédécesseur" .. | local mandat = args["Mandat" .. index] | ||
local successeur = args["Successeur" .. | local predecesseur = args["Prédécesseur" .. index] | ||
local successeur = args["Successeur" .. index] | |||
local charte = args["Charte"] or "defaut" | |||
-- Ne rien afficher si aucun contenu pertinent | |||
if not (titre or predecesseur or successeur) then | if not (titre or predecesseur or successeur) then | ||
return "" | return "" | ||
end | end | ||
local couleurFond = | -- Couleurs via module Charte | ||
local couleurTexte = | local couleurFond = frame:callParserFunction("#invoke:Charte|couleur", "charte=" .. charte .. "|type=titre") | ||
local couleurHr = | local couleurTexte = frame:callParserFunction("#invoke:Charte|couleur", "charte=" .. charte .. "|type=texte") | ||
local couleurHr = frame:callParserFunction("#invoke:Charte|couleur", "charte=" .. charte .. "|type=hr") | |||
-- HTML | |||
local html = {} | local html = {} | ||
table.insert(html, '<div style="margin: 0.5em 0; overflow: hidden; font-size: 90%;">') | table.insert(html, '<div style="margin: 0.5em 0; overflow: hidden; font-size: 90%;">') | ||
table.insert(html, '<div style="background-color: ' .. couleurFond .. ';color: ' .. couleurTexte .. ';text-align: center;padding: 0.5em;font-weight: bold;">') | |||
-- Titre et mandat | |||
table.insert(html, '<div style="background-color: ' .. couleurFond .. '; color: ' .. couleurTexte .. '; text-align: center; padding: 0.5em; font-weight: bold;">') | |||
table.insert(html, titre or "") | table.insert(html, titre or "") | ||
if mandat then | if mandat then | ||
| Ligne 23 : | Ligne 30 : | ||
end | end | ||
table.insert(html, '</div>') | table.insert(html, '</div>') | ||
-- Prédécesseur / Successeur | |||
table.insert(html, '<div style="display: flex; justify-content: space-between; align-items: center; padding: 0.5em;">') | table.insert(html, '<div style="display: flex; justify-content: space-between; align-items: center; padding: 0.5em;">') | ||
table.insert(html, '<div style="text-align: left; flex: 1;">') | table.insert(html, '<div style="text-align: left; flex: 1;">') | ||
| Ligne 28 : | Ligne 37 : | ||
table.insert(html, '← [[' .. predecesseur .. ']]') | table.insert(html, '← [[' .. predecesseur .. ']]') | ||
end | end | ||
table.insert(html, '</div><div style="flex: 0 0 auto; padding: 0 1em;">·</div><div style="text-align: right; flex: 1;">') | table.insert(html, '</div>') | ||
table.insert(html, '<div style="flex: 0 0 auto; padding: 0 1em;">·</div>') | |||
table.insert(html, '<div style="text-align: right; flex: 1;">') | |||
if successeur then | if successeur then | ||
table.insert(html, '[[' .. successeur .. ']] →') | table.insert(html, '[[' .. successeur .. ']] →') | ||
end | end | ||
table.insert(html, '</div></div>') | table.insert(html, '</div>') | ||
table.insert(html, '</div>') | |||
-- Ligne de séparation | |||
table.insert(html, '<hr style="background-color: ' .. couleurHr .. ';">') | table.insert(html, '<hr style="background-color: ' .. couleurHr .. ';">') | ||
table.insert(html, '</div>') | table.insert(html, '</div>') | ||
| Ligne 39 : | Ligne 53 : | ||
end | end | ||
function p. | -- Point d'entrée | ||
function p.main(frame) | |||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local | local out = {} | ||
for i = 1, 5 do | for i = 1, 5 do | ||
table.insert( | table.insert(out, genererBloc(args, i == 1 and "" or tostring(i), frame)) | ||
end | end | ||
return table.concat(out) | |||
return table.concat( | |||
end | end | ||
return p | return p | ||
Version du 31 mai 2025 à 10:33
La documentation pour ce module peut être créée à Module:Fonctions/doc
local p = {}
-- Génère un bloc HTML unique pour une fonction
local function genererBloc(args, index, frame)
local titre = args["Titre" .. index]
local mandat = args["Mandat" .. index]
local predecesseur = args["Prédécesseur" .. index]
local successeur = args["Successeur" .. index]
local charte = args["Charte"] or "defaut"
-- Ne rien afficher si aucun contenu pertinent
if not (titre or predecesseur or successeur) then
return ""
end
-- Couleurs via module Charte
local couleurFond = frame:callParserFunction("#invoke:Charte|couleur", "charte=" .. charte .. "|type=titre")
local couleurTexte = frame:callParserFunction("#invoke:Charte|couleur", "charte=" .. charte .. "|type=texte")
local couleurHr = frame:callParserFunction("#invoke:Charte|couleur", "charte=" .. charte .. "|type=hr")
-- HTML
local html = {}
table.insert(html, '<div style="margin: 0.5em 0; overflow: hidden; font-size: 90%;">')
-- Titre et mandat
table.insert(html, '<div style="background-color: ' .. couleurFond .. '; color: ' .. couleurTexte .. '; text-align: center; padding: 0.5em; font-weight: bold;">')
table.insert(html, titre or "")
if mandat then
table.insert(html, '<div style="font-weight: normal; font-size: 90%;">' .. mandat .. '</div>')
end
table.insert(html, '</div>')
-- Prédécesseur / Successeur
table.insert(html, '<div style="display: flex; justify-content: space-between; align-items: center; padding: 0.5em;">')
table.insert(html, '<div style="text-align: left; flex: 1;">')
if predecesseur then
table.insert(html, '← [[' .. predecesseur .. ']]')
end
table.insert(html, '</div>')
table.insert(html, '<div style="flex: 0 0 auto; padding: 0 1em;">·</div>')
table.insert(html, '<div style="text-align: right; flex: 1;">')
if successeur then
table.insert(html, '[[' .. successeur .. ']] →')
end
table.insert(html, '</div>')
table.insert(html, '</div>')
-- Ligne de séparation
table.insert(html, '<hr style="background-color: ' .. couleurHr .. ';">')
table.insert(html, '</div>')
return table.concat(html)
end
-- Point d'entrée
function p.main(frame)
local args = frame:getParent().args
local out = {}
for i = 1, 5 do
table.insert(out, genererBloc(args, i == 1 and "" or tostring(i), frame))
end
return table.concat(out)
end
return p