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

De Starfield Wiki
Aucun résumé des modifications
Balise : Révoqué
Annulation des modifications 729 de Kharmitch (discussion)
Balise : Annulation
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 = {}


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


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


-- Paramétrage par défaut
local config = {
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",
stub_title = "Cet article est une [[Aide:Ébauche|ébauche]].",
style_default = "sf-banner-simple",
stub_title_subject = "Cet article est une [[Aide:Ébauche|ébauche]] concernant %s.",
level_default = "sf-banner-neutral",
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 retournant un bandeau au format souhaité
-- Fonction générant un bandeau
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("Paramètres texte ou titre absents.")
error( "Merci de renseigner au moins le titre ou le texte")
end
end
local shape = args.forme or default.shape
-- Création du conteneur et des cellules qui le compose
local shape_class = shapes[shape]
if shape_class == nil then
error("Valeur inconnue pour le paramètre forme.")
end
local level = args.niveau or default.level
local res = mw.html.create( "div" )
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("banner")
res :addClass( "sf-banner" )
:addClass(shape_class)
:addClass( banner_styles[args.forme] or config.style_default )
:addClass(level_class)
:addClass( banner_levels[args.niveau] or config.level_default )


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 config.image_size
image = cells
image =  
:tag("div")
cells
:addClass("banner-cell banner-image")
:tag( "div" )
:wikitext(default.image_format:format(image, size, alt))
:addClass( "sf-banner-cell sf-banner-image" )
: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("banner-title")
:addClass( "sf-banner-title" )
:wikitext(title)
:wikitext(title)
:done()
:done()
end
end
 
if text then
if text then
html_text
html_text
Ligne 88 : Ligne 74 :


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


-- Fonction spécifique au bandeau de type ébauche
-- Fonction destinnée à être appelée dans les modèles
function p._stub(args)
local subjects = mw.loadData("Module:Bandeau/Ébauche")
local subject = args[1]
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.sujet
)
category = string.format(
default.stub_category_subject,
args[1]:lower()
)
else
title = default.stub_title
category = default.stub_category
end
return p._banner({
forme = 'article',
niveau = 'ébauche',
titre = title,
texte = default.stub_text,
}) .. category
end
 
-- Table de correspondance type de bandeau - fonction
local actions = {
banner = p._banner,
stub = p._stub,
}
 
function p.banner(frame)
function p.banner(frame)
local args
local args
Ligne 145 : Ligne 92 :
args = frame:getParent().args
args = frame:getParent().args
end
end
  return actions[shape](args)
return p._banner(args)
end
end


return p
return p

Version du 26 janvier 2023 à 15:07

Documentation[voir] [modifier] [purger]

Ce module implémente les modèles de bandeau.

Utilisation

Fonctions exportables :

  • banner(frame) – voir la documentation du modèle {{Bandeau}} ;
  • stub(frame) – voir la documentation du modèle {{ébauche}}.

Autres fonctions :

  • les fonctions ci-dessus avec un « _ » avant le nom peuvent être appelées directement depuis lua, avec les paramètres dans une table.

Modules externes et autres éléments dont ce module a besoin pour fonctionner :


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

local config = {
	image_format = "[[Fichier:%s|%spx|alt=%s|link=|class=noviewer]]",
	image_size = "x50",
	style_default = "sf-banner-simple",
	level_default = "sf-banner-neutral",
}

-- Fonction générant un bandeau
function p._banner(args)
	-- Contrôle des paramètres obligatoires
	
	local text = args.texte
	local title = args.titre
	
	if not text and not title then
		error( "Merci de renseigner au moins le titre ou le texte")
	end
	
	-- Création du conteneur et des cellules qui le compose
	
	local res = mw.html.create( "div" )
	local cells = mw.html.create()

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

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

	cells
		:tag('div')
			:addClass('sf-banner-cell')
			:newline()
			:wikitext(tostring(html_text))
			:newline()

	res	:node(cells)
	return tostring(res)
end

-- Fonction destinnée à être appelée dans les modèles
function p.banner(frame)
	local args
	if frame.args.texte or frame.args.titre then
		args = frame.args
	else
		args = frame:getParent().args
	end
	return p._banner(args)
end

return p