« Module:Charte » : différence entre les versions
Apparence
Aucun résumé des modifications Balise : Révoqué |
Aucun résumé des modifications Balise : Révoqué |
||
| Ligne 1 : | Ligne 1 : | ||
local p = {} | local p = {} | ||
-- Table des chartes avec leurs couleurs spécifiques | |||
local chartes = { | local chartes = { | ||
biographie = { | biographie = { | ||
titre | titre = "#6eacdc9c", | ||
soustitre | soustitre = "#a9c8e09c", | ||
hr | hr = "#6eacdc9c", | ||
}, | }, | ||
empire = { | empire = { | ||
titre | titre = "#993333b0", | ||
soustitre | soustitre = "#831f1fc7", | ||
hr | hr = "#993333b0", | ||
}, | }, | ||
geographie = { | geographie = { | ||
titre | titre = "#209a57d9", | ||
soustitre | soustitre = "#209a57a8", | ||
hr | hr = "#209a57d9", | ||
}, | }, | ||
darkgods = { | darkgods = { | ||
titre | titre = "#000000cc", | ||
soustitre | soustitre = "#000000a3", | ||
hr | hr = "#000000a3", | ||
color | color = "#ffffff", -- seul cas avec texte blanc | ||
}, | }, | ||
defaut = { | defaut = { | ||
titre | titre = "#eaecf0", | ||
soustitre | soustitre = "#a2a9b1", | ||
hr | hr = "#eaecf0", | ||
} | } | ||
} | } | ||
-- Table des titres automatiques des sous-titres selon la charte | |||
local soustitres = { | local soustitres = { | ||
biographie = "Informations biographiques", | biographie = "Informations biographiques", | ||
| Ligne 38 : | Ligne 40 : | ||
} | } | ||
-- Vérifie si une valeur est un code hexadécimal valide | |||
local function isHexCode(value) | local function isHexCode(value) | ||
return type(value) == "string" and mw.ustring.match(value, "^#%x%x%x%x%x%x%x?$") ~= nil | return type(value) == "string" and mw.ustring.match(value, "^#%x%x%x%x%x%x%x?$") ~= nil | ||
end | end | ||
-- Fonction | -- Fonction centrale pour récupérer une couleur selon la charte et le type | ||
local function couleurDirect(charte, type) | local function couleurDirect(charte, type) | ||
charte = charte or "defaut" | charte = mw.ustring.lower(charte or "defaut") | ||
type = type or "titre" | type = type or "titre" | ||
-- Cas spécial : couleur du texte | |||
if type == "texte" then | if type == "texte" then | ||
if chartes[charte] and chartes[charte].color then | if chartes[charte] and chartes[charte].color then | ||
return chartes[charte].color | return chartes[charte].color | ||
else | else | ||
return " | return "" -- pas de couleur forcée = hérite du style global | ||
end | end | ||
end | end | ||
-- Si on passe un code hexadécimal directement | |||
if isHexCode(charte) then | |||
return charte | |||
end | end | ||
-- Si la charte et le type existent dans la table | |||
if chartes[charte] and chartes[charte][type] then | |||
return chartes[charte][type] | return chartes[charte][type] | ||
end | end | ||
-- Sinon, retour vers la charte "defaut" | |||
return chartes["defaut"][type] or "#dddddd" | |||
end | end | ||
-- Fonction | -- Fonction appelée via #invoke sur le wiki | ||
function p.couleur(frameOrCharte, typeOrNil) | function p.couleur(frameOrCharte, typeOrNil) | ||
if type(frameOrCharte) == "table" and frameOrCharte.args then | if type(frameOrCharte) == "table" and frameOrCharte.args then | ||
local args = frameOrCharte.args | local args = frameOrCharte.args | ||
return couleurDirect(args["charte"], args["type"]) | return couleurDirect(args["charte"], args["type"]) | ||
else | else | ||
return couleurDirect(frameOrCharte, typeOrNil) | return couleurDirect(frameOrCharte, typeOrNil) | ||
end | end | ||
end | end | ||
-- Fonction pour | -- Fonction pour générer un nom de sous-titre automatique (si non défini dans le modèle) | ||
function p.soustitre(frame) | function p.soustitre(frame) | ||
local charte = frame.args["charte"] or "defaut" | local charte = frame.args["charte"] or "defaut" | ||
Version du 7 juin 2025 à 08:52
La documentation pour ce module peut être créée à Module:Charte/doc
local p = {}
-- Table des chartes avec leurs couleurs spécifiques
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",
color = "#ffffff", -- seul cas avec texte blanc
},
defaut = {
titre = "#eaecf0",
soustitre = "#a2a9b1",
hr = "#eaecf0",
}
}
-- Table des titres automatiques des sous-titres 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"
}
-- Vérifie si une valeur est un code hexadécimal valide
local function isHexCode(value)
return type(value) == "string" and mw.ustring.match(value, "^#%x%x%x%x%x%x%x?$") ~= nil
end
-- Fonction centrale pour récupérer une couleur selon la charte et le type
local function couleurDirect(charte, type)
charte = mw.ustring.lower(charte or "defaut")
type = type or "titre"
-- Cas spécial : couleur du texte
if type == "texte" then
if chartes[charte] and chartes[charte].color then
return chartes[charte].color
else
return "" -- pas de couleur forcée = hérite du style global
end
end
-- Si on passe un code hexadécimal directement
if isHexCode(charte) then
return charte
end
-- Si la charte et le type existent dans la table
if chartes[charte] and chartes[charte][type] then
return chartes[charte][type]
end
-- Sinon, retour vers la charte "defaut"
return chartes["defaut"][type] or "#dddddd"
end
-- Fonction appelée via #invoke sur le wiki
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
-- Fonction pour générer un nom de sous-titre automatique (si non défini dans le modèle)
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