Module:Charte
Apparence
La documentation pour ce module peut être créée à Module:Charte/doc
local p = {}
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 = "#000000cc",
soustitre = "#000000a3",
hr = "#000000a3",
texte = "#ffffff", -- couleur du texte explicitement définie
},
defaut = {
titre = "#eaecf0",
soustitre = "#a2a9b1",
hr = "#eaecf0",
}
}
local soustitres = {
biographie = "Informations biographiques",
empire = "Données impériales",
geographie = "Informations géographiques",
darkgods = "Entité obscure",
defaut = "Informations générales"
}
local function isHexCode(value)
return type(value) == "string" and mw.ustring.match(value, "^#%x%x%x%x%x%x%x?$") ~= nil
end
local function couleurDirect(charte, type)
charte = mw.ustring.lower(charte or "defaut")
type = type or "titre"
-- Si on demande une couleur de texte mais qu'aucune n’est définie → ne rien retourner
if type == "texte" then
if chartes[charte] and chartes[charte].texte then
return chartes[charte].texte
else
return "" -- chaîne vide : donc pas de color appliqué
end
end
if isHexCode(charte) then
return charte
end
if chartes[charte] and chartes[charte][type] then
return chartes[charte][type]
end
return chartes["defaut"][type] or "#dddddd"
end
function p.couleur(frameOrCharte, typeOrNil)
if type(frameOrCharte) == "table" and frameOrCharte.args then
local args = frameOrCharte.args
return couleurDirect(args["charte"], args["type"])
else
return couleurDirect(frameOrCharte, typeOrNil)
end
end
function p.soustitre(frame)
local charte = mw.ustring.lower(frame.args["charte"] or "defaut")
return soustitres[charte] or soustitres["defaut"]
end
return p