|
|
Ligne 1 : |
Ligne 1 : |
| -- Module dédié à la création de bandeaux en tous genres | | --Ce module implémente le modèle {{Bandeau}}. |
| | |
| | local p = {} |
|
| |
|
| local fun = {}
| | p.classStructureBoite = 'class="bandeau-simple"' |
| | p.styleStructureBoite = 'style="width:80%; margin:0 auto 1em; padding:0.5em; background:#f9f9f9; border-color:#aaa;"' |
| | p.styleStructureImage = 'style="display:table-cell; vertical-align:middle; width:50px;"' |
| | p.styleStructureTexte = 'style="display:table-cell; vertical-align:middle;"' |
|
| |
|
| function fun.metaBandeauAvertissement(frame)
| | local TableBuilder = require('Module:TableBuilder') |
| local pframe = frame:getParent()
| |
| local arguments = pframe.args
| |
| return fun.do_metaBandeauAvertissement(arguments)
| |
| end
| |
|
| |
|
| -- Squelette d'un bandeau d'avertissement
| | function p.structure(frame) |
| function fun.do_metaBandeauAvertissement(arguments) | | args = frame:getParent().args |
| local result = ""
| | local tab = TableBuilder.new() |
| local niveau = arguments.niveau or ""
| |
| local bClass = mw.ustring.gsub(niveau,"é","e")
| |
| local icone = ""
| |
| local texte = ""
| |
|
| |
| -- Icônes prédéfinies
| |
| local iconeTable = {
| |
| grave = "Fairytale no.svg",
| |
| ["modéré"] = "Emblem-important.svg",
| |
| information = "Information_icon.svg",
| |
| ["ébauche"] = "Nuvola_apps_kedit.svg"
| |
| }
| |
| | | |
| -- Utiliser l'icône fournie s'il y a lieu, ou prendre parmi celles de la table | | tab.insert(structureHtml('div', p.classStructureBoite, p.styleStructureBoite, 'Lorem')) |
| if(arguments["icône-complexe"] ~= nil and arguments["icône-complexe"] ~= "") then
| |
| icone = arguments["icône-complexe"]
| |
| else
| |
| icone = "<div style=\"width:45px; text-align:center\">[[Fichier:" .. (arguments["icône"] or iconeTable[arguments.niveau] or "Icon apps query.svg") .. "|45x35px|alt=|link=]]</div>"
| |
| end
| |
|
| |
| -- Texte du bandeau
| |
| if(arguments.texte ~= nil) then
| |
| texte = "<div class=\"bandeau-texte\">" .. arguments.texte .. "</div>"
| |
| end
| |
| | | |
| -- Mise en boîte | | return tab.concat() |
| result = "<div " .. (arguments.id or "") .. "class=\"plainlinks bandeau-niveau-" .. bClass .. " bandeau js-no-interprojets\"><table style=\"background-color:transparent\"><tr><td class=\"bandeau-icone\">" .. icone .. "</td><td><div class=\"bandeau-titre\"><strong>" .. (arguments.titre or "Pas de titre") .. "</strong>" .. (arguments.date or "") .. "</div>" .. texte .. "</td></tr></table>" .. (arguments["supplément"] or "") .. "</div>"
| |
| | |
| return result
| |
| end | | end |
|
| |
|
| function fun.ebauche(frame) | | function structureHtml(balise, class, style, contenu) |
| local pframe = frame:getParent()
| | local tab = TableBuilder.new() |
| local arguments = pframe.args
| |
| return fun.do_ebauche(arguments)
| |
| end
| |
| | |
| function fun.do_ebauche(arguments)
| |
| -- Données relatives aux différents paramètres possibles du modèle | |
| -- Seront déplacées en sous-page dès que loadData sera activé
| |
| -- local data = mw.loadData("Module:Bandeau/ébauche")
| |
| local data = {
| |
| football = {"Soccer.svg", "le [[football]]"},
| |
| footballeur = {"football", "un [[Portail:Football|footballeur]]"},
| |
| ["hip hop"] = {"redirection", "hip-hop"},
| |
| ["hip-hop"] = {"BandeauPortailHipHopSmall-fr.svg", "le [[Portail:Hip-hop|hip-hop]]"},
| |
| histoire = {"Pierre_Mignard_001.jpg", "l’[[histoire]]"},
| |
| Italie = {"Italy looking like the flag.svg", "l’[[Portail:Italie|Italie]]"},
| |
| jardinage = {"Extracted pink rose.png", "le [[jardinage]] et l’[[horticulture]]"},
| |
| lac = {"Icon river reservoir.svg", "un [[lac]]"},
| |
| lapin = {"Lapin01.svg", "la [[cuniculture]]", "Cuniculture"}
| |
| }
| |
| | | |
| local index = 1 | | tab.insert('<' + balise + ' ') |
| local inconnu = {false, ""}
| | if class and style then |
| local newTheme = 0
| | tab.insert(class) |
| local nomTheme = arguments[1]
| | .insert(' ') |
| local icones = {}
| | .insert(style) |
| local sujets = {}
| | else |
| local categories = {}
| | tab.insert(class or style) |
|
| |
| -- Récupération des données sur tous les thèmes
| |
| while(arguments[index] ~= nil) do
| |
| -- Récupération des données relatives au thème
| |
| theme = data[nomTheme]
| |
| if(theme ~= nil) then
| |
| if(theme[1] == "alias" or theme[1] == "redirection") then
| |
| -- Cas de redirection
| |
| newTheme = newTheme + 1
| |
| nomTheme = theme[2]
| |
| else
| |
| -- Cas normal
| |
| newTheme = 0
| |
| -- Gestion de l'icône
| |
| if(theme[1] ~= nil) then
| |
| local cibleIcone = data[theme[1]]
| |
| -- Le nom de l'icône est-il une référence directe à un autre thème ?
| |
| if(cibleIcone == nil or cibleIcone[1] == "alias" or cibleIcone[1] == "redirection") then
| |
| -- Non : on récupère le nom du fichier
| |
| icones[#icones+1] = theme[1]
| |
| else
| |
| -- Oui : on récupère l'icône de l'autre thème
| |
| icones[#icones+1] = cibleIcone[1]
| |
| end
| |
| end
| |
| -- Gestion du sujet
| |
| if(theme[2] ~= nil) then
| |
| sujets[#sujets+1] = theme[2]
| |
| end
| |
| -- Gestion de la catégorie
| |
| if(theme[3] ~= nil) then
| |
| categories[#categories+1] = theme[3]
| |
| else
| |
| -- Par défaut, la catégorie correspond au thème
| |
| categories[#categories+1] = nomTheme
| |
| end
| |
| end
| |
| else | |
| -- Thème inconnu : on le mémorise et on passe au suivant
| |
| newTheme = 0
| |
| inconnu[1] = true
| |
| inconnu[2] = inconnu[2] .. arguments[index] .. " "
| |
| end
| |
| -- Passage éventuel au thème suivant
| |
| if(newTheme > 2) then
| |
| -- Prévention des boucles infinies
| |
| newTheme = 0
| |
| end
| |
| if(newTheme == 0) then
| |
| -- Nouveau thème (non issu d'une redirection)
| |
| index = index + 1
| |
| nomTheme = arguments[index]
| |
| end
| |
| end | | end |
| | | tab.insert('>') |
| -- Génération du bandeau
| | .insert(contenu) |
| local multiIcone = ""
| | .insert('</' + balise + '>') |
| local taille = "45x35px"
| | |
| -- Réduire les icônes si elles sont trop nombreuses
| | return tab.concat() |
| if(#icones > 3) then
| |
| taille = "35x25px"
| |
| end
| |
| if(#icones > 0) then
| |
| for i = 1, #icones do
| |
| multiIcone = multiIcone .. "[[Image:" .. icones[i] .. "|" .. taille .. "|alt=|link=]]"
| |
| -- Passage sur la deuxième ligne
| |
| if(#icones > 3 and i == math.floor((#icones+1)/2)) then
| |
| multiIcone = multiIcone .. "</span><br /><span style=\"white-space:nowrap;word-spacing:5px\">"
| |
| elseif(i ~= #icones) then
| |
| multiIcone = multiIcone .. " "
| |
| end
| |
| end
| |
| multiIcone = "<div style=\"text-align:center;white-space:nowrap\"><span style=\"white-space:nowrap;word-spacing:5px\">" .. multiIcone .. "</span></div>"
| |
| end
| |
|
| |
| -- Texte du bandeau, contenant les sujets
| |
| local texteSuj = "Cet article est une [[Aide:Ébauche|ébauche]]"
| |
| if(#sujets > 0) then
| |
| texteSuj = texteSuj .. " concernant "
| |
| for i = 1, #sujets do
| |
| texteSuj = texteSuj .. sujets[i]
| |
| if(i < #sujets-1) then
| |
| texteSuj = texteSuj .. ", "
| |
| elseif(i == #sujets-1) then
| |
| texteSuj = texteSuj .. " et "
| |
| end
| |
| end
| |
| end
| |
| texteSuj = texteSuj .. ".\n"
| |
|
| |
| local texteCat = ""
| |
| -- Ne pas catégoriser si nocat est présent
| |
| if(arguments.nocat == nil) then
| |
| if(#categories > 0) then
| |
| for i = 1, #categories do
| |
| texteCat = texteCat .. "[[Catégorie:Wikipédia:ébauche " .. categories[i] .. "]]\n"
| |
| end
| |
| else
| |
| texteCat = "[[Catégorie:Wikipédia:ébauche]]\n"
| |
| end
| |
| end
| |
|
| |
| -- Préparation de l'appel du modèle de méta-bandeau
| |
| local metaArgs = {
| |
| niveau = "ébauche",
| |
| ["icône-complexe"] = multiIcone,
| |
| titre = texteSuj
| |
| }
| |
|
| |
| return fun.do_metaBandeauAvertissement(metaArgs) .. "\n" .. texteCat | |
|
| |
| end | | end |
|
| |
|
| return fun | | return p |
--Ce module implémente le modèle Modèle:Bandeau.
local p = {}
p.classStructureBoite = 'class="bandeau-simple"'
p.styleStructureBoite = 'style="width:80%; margin:0 auto 1em; padding:0.5em; background:#f9f9f9; border-color:#aaa;"'
p.styleStructureImage = 'style="display:table-cell; vertical-align:middle; width:50px;"'
p.styleStructureTexte = 'style="display:table-cell; vertical-align:middle;"'
local TableBuilder = require('Module:TableBuilder')
function p.structure(frame)
args = frame:getParent().args
local tab = TableBuilder.new()
tab.insert(structureHtml('div', p.classStructureBoite, p.styleStructureBoite, 'Lorem'))
return tab.concat()
end
function structureHtml(balise, class, style, contenu)
local tab = TableBuilder.new()
tab.insert('<' + balise + ' ')
if class and style then
tab.insert(class)
.insert(' ')
.insert(style)
else
tab.insert(class or style)
end
tab.insert('>')
.insert(contenu)
.insert('</' + balise + '>')
return tab.concat()
end
return p