Aller au contenu

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

De Wikiquestia
Aucun résumé des modifications
Balise : Révoqué
Aucun résumé des modifications
Balises : Révocation manuelle Révoqué
Ligne 1 : Ligne 1 :
local p = {}
local p = {}


local chartes = {
local chartes = {
    biographie = {
biographie = {
        titre    = "#6eacdc9c",
titre    = "#6eacdc9c",
        soustitre = "#a9c8e09c",
soustitre = "#a9c8e09c",
        hr        = "#6eacdc9c"
hr        = "#6eacdc9c"
    },
},
    empire = {
empire = {
        titre    = "#993333b0",
titre    = "#993333b0",
        soustitre = "#831f1fc7",
soustitre = "#831f1fc7",
        hr        = "#993333b0"
hr        = "#993333b0"
    },
},
    geographie = {
geographie = {
        titre    = "#209a57d9",
titre    = "#209a57d9",
        soustitre = "#209a57a8",
soustitre = "#209a57a8",
        hr        = "#209a57d9"
hr        = "#209a57d9"
    },
},
    darkgods = {
darkgods = {
        titre    = "#ffffff", -- Titres blancs uniquement pour darkgods
titre    = "#000000cc",
        soustitre = "#ffffff", -- Sous-titres blancs uniquement pour darkgods
soustitre = "#000000a3",
        hr        = "#000000a3",
hr        = "#000000a3",
        texte    = "#ffffff"
texte    = "#ffffff"
    },
},
    defaut = {
defaut = {
        titre    = "#eaecf0",
titre    = "#eaecf0",
        soustitre = "#a2a9b1",
soustitre = "#a2a9b1",
        hr        = "#eaecf0"
hr        = "#eaecf0"
    }
}
}
}


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"
}
}


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


local function couleurDirect(charte, type)
local function couleurDirect(charte, type)
    charte = mw.ustring.lower(charte or "defaut")
charte = mw.ustring.lower(charte or "defaut")
    type = type or "titre"
type = type or "titre"
 
    -- Si darkgods et type titre ou soustitre, forcer blanc
    if charte == "darkgods" and (type == "titre" or type == "soustitre") then
        return "#ffffff"
    end


    if isHexCode(charte) then
if isHexCode(charte) then
        return charte
return charte
    end
end


    if chartes[charte] and chartes[charte][type] then
if chartes[charte] and chartes[charte][type] then
        return chartes[charte][type]
return chartes[charte][type]
    end
end


    return chartes["defaut"][type] or "#dddddd"
return chartes["defaut"][type] or "#dddddd"
end
end


-- Fonction principale appelée avec #invoke
-- Fonction principale appelée avec #invoke
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


-- Renvoie un style de couleur texte complet uniquement si défini
-- Renvoie un style de couleur texte complet uniquement si défini
function p.styleTexte(frame)
function p.styleTexte(frame)
    local charte = mw.ustring.lower(frame.args["charte"] or "defaut")
local charte = mw.ustring.lower(frame.args["charte"] or "defaut")
    local couleurTexte = chartes[charte] and chartes[charte].texte
local couleurTexte = chartes[charte] and chartes[charte].texte
    if couleurTexte then
if couleurTexte then
        return 'style="color: ' .. couleurTexte .. ';"'
return 'style="color: ' .. couleurTexte .. ';"'
    else
else
        return ""
return ""
    end
end
end
end


-- Fournit un nom de sous-titre générique
-- Fournit un nom de sous-titre générique
function p.soustitre(frame)
function p.soustitre(frame)
    local charte = mw.ustring.lower(frame.args["charte"] or "defaut")
local charte = mw.ustring.lower(frame.args["charte"] or "defaut")
    return soustitres[charte] or soustitres["defaut"]
return soustitres[charte] or soustitres["defaut"]
end
end


return p
return p

Version du 7 juin 2025 à 09:12

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"
	},
	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"

	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

-- Fonction principale appelée avec #invoke
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

-- Renvoie un style de couleur texte complet uniquement si défini
function p.styleTexte(frame)
	local charte = mw.ustring.lower(frame.args["charte"] or "defaut")
	local couleurTexte = chartes[charte] and chartes[charte].texte
	if couleurTexte then
		return 'style="color: ' .. couleurTexte .. ';"'
	else
		return ""
	end
end

-- Fournit un nom de sous-titre générique
function p.soustitre(frame)
	local charte = mw.ustring.lower(frame.args["charte"] or "defaut")
	return soustitres[charte] or soustitres["defaut"]
end

return p