Aller au contenu

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

De Wikiquestia
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 1 : Ligne 1 :
local p = {}
local p = {}


-- Tableau des chartes pré-définies
local chartes = {
local chartes = {
   biographie = {
   biographie = {
Ligne 34 : Ligne 35 :
   }
   }
}
}
-- Textes par défaut selon la charte (NOUVELLE TABLE)
 
-- Textes par défaut selon la charte
local soustitres = {
local soustitres = {
biographie = "Informations biographiques",
  biographie = "Informations biographiques",
empire    = "Données impériales",
  empire    = "Données impériales",
geographie = "Informations géographiques",
  geographie = "Informations géographiques",
darkgods  = "Entité obscure",
  darkgods  = "Entité obscure",
defaut    = "Informations générales"
  defaut    = "Informations générales",
}
}


-- Fonction pour vérifier si c’est un code hex
-- Fonction pour détecter un code hex (#xxxxxx ou #xxxxxxx)
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 principale de couleur
-- 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 charte = args["charte"] or "defaut"
local type  = args["type"]  or "titre"
  local type  = args["type"]  or "titre"


if type == "texte" then
  -- Si la "charte" est un code hexadécimal, l'utiliser directement comme couleur de fond
if chartes[charte] and chartes[charte].color then
  if isHexCode(charte) then
return chartes[charte].color
    if type == "texte" then
else
      return "#000000" -- texte noir par défaut sur fond clair
return "#000000"
    else
end
      return charte
end
    end
  end


if type == "soustitre" then
  -- Si type=texte et color personnalisé défini dans la charte
-- si la charte définit bien une couleur de sous-titre, on l'utilise
  if type == "texte" then
if chartes[charte] and chartes[charte].soustitre then
    if chartes[charte] and chartes[charte].color then
return chartes[charte].soustitre
      return chartes[charte].color
else
    else
-- sinon, on tombe sur la couleur par défaut
      return "#000000"
return chartes["defaut"].soustitre
    end
end
  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


if isHexCode(charte) then
  -- Autres types (titre, hr, etc.)
return charte
  if chartes[charte] and chartes[charte][type] then
elseif chartes[charte] and chartes[charte][type] then
    return chartes[charte][type]
return chartes[charte][type]
  else
else
    return chartes["defaut"][type] or "#dddddd"
return chartes["defaut"][type] or "#dddddd"
  end
end
end
end


-- Fonction pour afficher le texte par défaut du sous-titre
-- Fonction pour renvoyer un texte de sous-titre par défaut
function p.soustitre(frame)
function p.soustitre(frame)
local charte = frame.args["charte"] or "defaut"
  local charte = frame.args["charte"] or "defaut"
charte = mw.ustring.lower(charte)
  charte = mw.ustring.lower(charte)
return soustitres[charte] or soustitres["defaut"]
  return soustitres[charte] or soustitres["defaut"]
end
end


return p
return p

Version du 27 juin 2025 à 05:53

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