Aller au contenu

« Module:Charte » : différence entre les versions

De Wikiquestia
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   = frame.args
   local args = frame.args
   local charte = args["charte"] or "defaut"
   local couleurOuCharte = args["couleur"] or args["charte"] or "defaut"
   local type   = args["type"]   or "titre"
   local type = args["type"] or "titre"


   -- Si la "charte" est un code hexadécimal, l'utiliser directement comme couleur de fond
   -- Si l'utilisateur fournit un code hexadécimal direct
   if isHexCode(charte) then
   if isHexCode(couleurOuCharte) then
     if type == "texte" then
     if type == "texte" then
       return "#000000" -- texte noir par défaut sur fond clair
       return "#000000" -- texte noir par défaut
     else
     else
       return charte
       return couleurOuCharte
     end
     end
   end
   end


   -- Si type=texte et color personnalisé défini dans la charte
   -- Si type=texte et une couleur de texte personnalisée est définie
   if type == "texte" then
   if type == "texte" then
     if chartes[charte] and chartes[charte].color then
     if chartes[couleurOuCharte] and chartes[couleurOuCharte].color then
       return chartes[charte].color
       return chartes[couleurOuCharte].color
     else
     else
       return "#000000"
       return "#000000"
Ligne 74 : Ligne 74 :
   end
   end


   -- Type soustitre : renvoie couleur spécifique ou valeur par défaut
   -- Si type=soustitre
   if type == "soustitre" then
   if type == "soustitre" then
     if chartes[charte] and chartes[charte].soustitre then
     if chartes[couleurOuCharte] and chartes[couleurOuCharte].soustitre then
       return chartes[charte].soustitre
       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[charte] and chartes[charte][type] then
   if chartes[couleurOuCharte] and chartes[couleurOuCharte][type] then
     return chartes[charte][type]
     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