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

1 482 octets ajoutés ,  29 janvier 2023
aucun résumé des modifications
Page créée avec « -- Module standardisant la création et le format des bandeaux -- Inspiré de https://fr.wikipedia.org/wiki/Module:Bandeau local p = {} local banner_styles = { ["simple"] = "sf-banner-simple", ["article"] = "sf-banner-article", ["section"] = "sf-banner-section", } local banner_levels = { ["neutre"] = "sf-banner-neutral", ["grave"] = "sf-banner-serious", ["modéré"] = "sf-banner-moderate", ["information"] = "sf-banner-info", ["ébauche"] = "sf-banner-s... »
 
Aucun résumé des modifications
 
(8 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
-- Module standardisant la création et le format des bandeaux
-- Inspiré de https://fr.wikipedia.org/wiki/Module:Bandeau
local p = {}
local p = {}


local banner_styles = {
-- Types de bandeau autorisés
["simple"] = "sf-banner-simple",
local shapes = {
["article"] = "sf-banner-article",
article = "banner-article",
["section"] = "sf-banner-section",
note = "banner-note",
section = "banner-section",
simple = "banner-simple",
}
}


local banner_levels = {
-- Niveaux d'information autorisés
["neutre"] = "sf-banner-neutral",
local levels = {
["grave"] = "sf-banner-serious",
ebauche = "banner-stub",
["modéré"] = "sf-banner-moderate",
grave = "banner-serious",
["information"] = "sf-banner-info",
information = "banner-info",
["ébauche"] = "sf-banner-stub",
modere = "banner-moderate",
neutre = "banner-neutral",
}
}
levels["modéré"] = levels.modere
levels["ébauche"] = levels.ebauche


local config = {
-- Paramétrage par défaut
local default = {
shape = "simple",
level = "information",
image_format = "[[Fichier:%s|%spx|alt=%s|link=|class=noviewer]]",
image_format = "[[Fichier:%s|%spx|alt=%s|link=|class=noviewer]]",
image_size = "x50",
image_size = "x50",
style_default = "sf-banner-simple",
stub_title = "Cet article est une [[Aide:Ébauche|ébauche]].",
level_default = "sf-banner-neutral",
stub_title_subject = "Cet article est une [[Aide:Ébauche|ébauche]] concernant %s.",
stub_category = "[[Catégorie:Ébauche]]",
stub_category_subject = "[[Catégorie:Ébauche (%s)]]",
stub_text = "Vous pouvez partager vos connaissances en l'améliorant ('''[[Aide:Modifier une page|comment ?]]''') selon nos [[Aide:Accueil#Politique de Starfield Wiki|conventions]].",
}
}


-- Fonction générant un bandeau
-- Fonction retournant un bandeau au format souhaité
function p._banner(args)
function p._banner(args)
-- Contrôle des paramètres obligatoires
local text = args.texte
local text = args.texte
local title = args.titre
local title = args.titre
if not text and not title then
if not text and not title then
error( "Merci de renseigner au moins le titre ou le texte")
error("Paramètres texte ou titre absents.")
end
end
-- Création du conteneur et des cellules qui le compose
local shape = args.forme or default.shape
local shape_class = shapes[shape]
if shape_class == nil then
error("Valeur inconnue pour le paramètre forme.")
end
local res = mw.html.create( "div" )
local level = args.niveau or default.level
local level_class = levels[level]
if level_class == nil then
error("Valeur inconnue pour le paramètre niveau.")
end
 
local res = mw.html.create("div")
local cells = mw.html.create()
local cells = mw.html.create()


res :addClass( "sf-banner" )
res :addClass("banner")
:addClass( banner_styles[args.forme] or config.style_default )
:addClass(shape_class)
:addClass( banner_levels[args.niveau] or config.level_default )
:addClass(level_class)
:addClass("noexcerpt")


local image = args.image
local image = args.image
if image then
if image then
local alt = args["image légende"] or ""
local alt = args["image légende"] or ""
local size = args['image taille'] or config.image_size
local size = args["image taille"] or default.image_size
image =  
image = cells
cells
:tag("div")
:tag( "div" )
:addClass("banner-cell banner-image")
:addClass( "sf-banner-cell sf-banner-image" )
:wikitext(default.image_format:format(image, size, alt))
:wikitext(config.image_format:format(image, size, alt))
end
end
 
local html_text = mw.html.create()
local html_text = mw.html.create()
 
if title then
if title then
html_text = html_text
html_text = html_text
:tag( "strong" )
:tag("strong")
:addClass( "sf-banner-title" )
:addClass("banner-title")
:wikitext(title)
:wikitext(title)
:done()
:done()
end
if text then
html_text
if text then
:newline()
:newline()
:wikitext(text)
end
elseif text then
html_text
html_text
:newline()
:newline()
:newline()
:wikitext(text)
:wikitext(text)
Ligne 74 : Ligne 92 :


cells
cells
:tag('div')
:tag("div")
:addClass('sf-banner-cell')
:addClass("banner-cell")
:newline()
:newline()
:wikitext(tostring(html_text))
:wikitext(tostring(html_text))
Ligne 84 : Ligne 102 :
end
end


-- Fonction destinnée à être appelée dans les modèles
-- Fonction spécifique au bandeau de type ébauche
function p.banner(frame)
function p._stub(args)
local args
local subjects = mw.loadData("Module:Bandeau/Ébauche")
if frame.args.texte or frame.args.titre then
local subject = args[1]
args = frame.args
if subject ~= nil then
subject = subjects[subject:lower()]
end
local title
local category
if subject ~= nil then
title = string.format(
default.stub_title_subject,
subject.subject
)
category = string.format(
default.stub_category_subject,
args[1]:lower()
)
else
else
args = frame:getParent().args
title = default.stub_title
category = default.stub_category
end
return p._banner({
forme = "article",
niveau = "ébauche",
titre = title,
texte = default.stub_text,
image = subject.image,
["image taille"] = subject.size,
}) .. category
end
 
function get_args(frame)
local args = {}
local argsParent = frame:getParent().args
for cle, val in pairs(argsParent) do
if val then
args[cle] = mw.text.trim(val)
end
end
end
return p._banner(args)
return args
end
 
-- Fonctions destinées à être appelées dans les modèles
 
function p.banner(frame)
return p._banner(get_args(frame))
end
 
function p.stub(frame)
return p._stub(get_args(frame))
end
end


return p
return p