« Module:Charte » : différence entre les versions
Apparence
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 52 : | Ligne 52 : | ||
-- Fonction principale pour renvoyer une couleur selon charte et type | -- Fonction principale pour renvoyer une couleur selon charte et type | ||
function p.couleur(frame) | function p.couleur(frame) | ||
local args | local args = frame.args | ||
local | local couleurOuCharte = args["couleur"] or args["charte"] or "defaut" | ||
local type | local type = args["type"] or "titre" | ||
-- Si | -- Si l'utilisateur fournit un code hexadécimal direct | ||
if isHexCode( | if isHexCode(couleurOuCharte) then | ||
if type == "texte" then | if type == "texte" then | ||
return "#000000" -- texte noir par défaut | return "#000000" -- texte noir par défaut | ||
else | else | ||
return | return couleurOuCharte | ||
end | end | ||
end | end | ||
-- Si type=texte et | -- Si type=texte et une couleur de texte personnalisée est définie | ||
if type == "texte" then | if type == "texte" then | ||
if chartes[ | if chartes[couleurOuCharte] and chartes[couleurOuCharte].color then | ||
return chartes[ | return chartes[couleurOuCharte].color | ||
else | else | ||
return "#000000" | return "#000000" | ||
| Ligne 74 : | Ligne 74 : | ||
end | end | ||
-- | -- Si type=soustitre | ||
if type == "soustitre" then | if type == "soustitre" then | ||
if chartes[ | if chartes[couleurOuCharte] and chartes[couleurOuCharte].soustitre then | ||
return chartes[ | return chartes[couleurOuCharte].soustitre | ||
else | else | ||
return chartes["defaut"].soustitre | return chartes["defaut"].soustitre | ||
| Ligne 84 : | Ligne 84 : | ||
-- Autres types (titre, hr, etc.) | -- Autres types (titre, hr, etc.) | ||
if chartes[ | if chartes[couleurOuCharte] and chartes[couleurOuCharte][type] then | ||
return chartes[ | return chartes[couleurOuCharte][type] | ||
else | else | ||
return chartes["defaut"][type] or "#dddddd" | return chartes["defaut"][type] or "#dddddd" | ||
Version du 27 juin 2025 à 06:03
La documentation pour ce module peut être créée à Module:Charte/doc
local p = {}
-- Tableau des chartes pré-définies
local chartes = {
biographie = {
titre = "#6eacdc9c",
soustitre = "#a9c8e09c",
hr = "#6eacdc9c",
},
empire = {
titre = "#993333b0",
soustitre = "#831f1fc7",
hr = "#993333b0",
},
geographie = {
titre = "#209a57d9",
soustitre = "#209a57a8",
hr = "#209a57d9",
},
darkgods = {
titre = "#000000",
soustitre = "#000000e8",
hr = "#000000",
color = "#ffffff",
},
langue = {
titre = "#9b59b6b0", -- violet principal
soustitre = "#a674c8a8", -- violet plus clair
hr = "#9b59b6b0", -- même que le titre
},
defaut = {
titre = "#eaecf0",
soustitre = "#a2a9b1",
hr = "#eaecf0",
}
}
-- Textes par défaut selon la charte
local soustitres = {
biographie = "Informations biographiques",
empire = "Données impériales",
geographie = "Informations géographiques",
darkgods = "Entité obscure",
defaut = "Informations générales",
}
-- Fonction pour détecter un code hex (#xxxxxx ou #xxxxxxx)
local function isHexCode(value)
return type(value) == "string" and mw.ustring.match(value, "^#%x%x%x%x%x%x%x?$") ~= nil
end
-- Fonction principale pour renvoyer une couleur selon charte et type
function p.couleur(frame)
local args = frame.args
local couleurOuCharte = args["couleur"] or args["charte"] or "defaut"
local type = args["type"] or "titre"
-- Si l'utilisateur fournit un code hexadécimal direct
if isHexCode(couleurOuCharte) then
if type == "texte" then
return "#000000" -- texte noir par défaut
else
return couleurOuCharte
end
end
-- Si type=texte et une couleur de texte personnalisée est définie
if type == "texte" then
if chartes[couleurOuCharte] and chartes[couleurOuCharte].color then
return chartes[couleurOuCharte].color
else
return "#000000"
end
end
-- Si type=soustitre
if type == "soustitre" then
if chartes[couleurOuCharte] and chartes[couleurOuCharte].soustitre then
return chartes[couleurOuCharte].soustitre
else
return chartes["defaut"].soustitre
end
end
-- Autres types (titre, hr, etc.)
if chartes[couleurOuCharte] and chartes[couleurOuCharte][type] then
return chartes[couleurOuCharte][type]
else
return chartes["defaut"][type] or "#dddddd"
end
end
-- Fonction pour renvoyer un texte de sous-titre par défaut
function p.soustitre(frame)
local charte = frame.args["charte"] or "defaut"
charte = mw.ustring.lower(charte)
return soustitres[charte] or soustitres["defaut"]
end
return p