Module:Charte
Apparence
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 charte = args["charte"] or "defaut"
local type = args["type"] or "titre"
-- Si la "charte" est un code hexadécimal, l'utiliser directement comme couleur de fond
if isHexCode(charte) then
if type == "texte" then
return "#000000" -- texte noir par défaut sur fond clair
else
return charte
end
end
-- Si type=texte et color personnalisé défini dans la charte
if type == "texte" then
if chartes[charte] and chartes[charte].color then
return chartes[charte].color
else
return "#000000"
end
end
-- Type soustitre : renvoie couleur spécifique ou valeur par défaut
if type == "soustitre" then
if chartes[charte] and chartes[charte].soustitre then
return chartes[charte].soustitre
else
return chartes["defaut"].soustitre
end
end
-- Autres types (titre, hr, etc.)
if chartes[charte] and chartes[charte][type] then
return chartes[charte][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