« Module:Bandeau » : différence entre les versions
Aller à la navigation
Aller à la recherche
Modèle>Hlm Z. Aucun résumé des modifications |
Modèle>Hlm Z. Aucun résumé des modifications |
||
| Ligne 11 : | Ligne 11 : | ||
local p = {} | local p = {} | ||
local format = mw.ustring.format | |||
p.classeSimple = 'simple' | p.classeSimple = 'simple' | ||
p.niveauNeutre = 'neutre' | p.niveauNeutre = 'neutre' | ||
| Ligne 28 : | Ligne 29 : | ||
end | end | ||
return _bandeau(args) | return p._bandeau(args) | ||
end | end | ||
function _bandeau(argsBandeau) | function p._bandeau(argsBandeau) | ||
args = argsBandeau | args = argsBandeau | ||
local res = mw.html.create('div') | local res = mw.html.create('div') | ||
| Ligne 39 : | Ligne 40 : | ||
:addClass('test-bandeau-niveau-' .. (args.niveau or 'neutre')) | :addClass('test-bandeau-niveau-' .. (args.niveau or 'neutre')) | ||
:addClass('plainlinks') | :addClass('plainlinks') | ||
:cssText(args.style) | :cssText(args.style) --Provisoire | ||
if args.image then | if args.image then | ||
local | local imageFormat = res:tag('div') | ||
:addClass('test-bandeau-image') | :addClass('test-bandeau-image') | ||
if mw.ustring.sub(args.image, 1, 1) == '[' then | if mw.ustring.sub(args.image, 1, 1) == '[' then | ||
imageFormat:wikitext(args.image) | |||
else | else | ||
imageFormat:wikitext(format('[[Fichier:%s|40px|alt=%s|link=]]', | |||
args.image, | args.image, | ||
args['légende'] or '')) | args['légende'] or '')) | ||
| Ligne 59 : | Ligne 60 : | ||
return tostring(res) | return tostring(res) | ||
end | |||
function p.bandeauAvertissement(args) | |||
local icones = { | |||
grave = 'Fairytale no.svg', | |||
['modéré'] = 'Emblem-important.svg', | |||
information = 'Information icon.svg', | |||
['ébauche'] = 'Nuvola apps kedit.svg' | |||
} | |||
local htmlTexte = mw.html.create() | |||
:tag('strong') | |||
:wikitext(args.titre or erreur('Paramètre |titre= introuvable')) | |||
:done() | |||
:tag('br') | |||
:done() | |||
:wikitext(args.texte) | |||
local bandeau = p._bandeau({ | |||
classe = 'article', | |||
niveau = args.niveau, | |||
image = args['icône'] or icones[niveau], | |||
texte = tostring(htmlTexte) | |||
}) | |||
return bandeau | |||
end | end | ||
Version du 25 juillet 2014 à 21:56
La documentation pour ce module peut être créée à Module:Bandeau/doc
--Ce module implémente le modèle {{Bandeau}}.
--Standardisation des bandeaux ([[Catégorie:Modèle de bandeau]]).
--Créer une fonction exportable pour le modèle {{Bandeau}} (ns:all).
--Créer une fonction exportable pour les bandeaux d'article (ns:0).
--Créer une fonction exportable pour les bandeaux de section (ns:0).
--Créer une fonction exportable pour les bandeaux d'ébauche (ns:0).
--Créer une fonction exportable pour les bandeaux de discussion (ns:1).
--Créer une fonction exportable pour les bandeaux système (ns:8).
local p = {}
local format = mw.ustring.format
p.classeSimple = 'simple'
p.niveauNeutre = 'neutre'
p.styleStructureImage = 'display:table-cell; vertical-align:middle; width:50px;'
p.styleStructureTexte = 'display:table-cell; vertical-align:middle;'
p.erreurArgumentTitre = 'Paramètre « texte » manquant'
function p.bandeau(frame)
local args = {}
local argsParent = frame:getParent().args
--Paramètres vides interprétés par Lua
for cle, val in pairs(argsParent) do
if val ~= '' then
args[cle] = val
end
end
return p._bandeau(args)
end
function p._bandeau(argsBandeau)
args = argsBandeau
local res = mw.html.create('div')
res
:addClass('test-bandeau-' .. (args.classe or 'simple'))
:addClass('test-bandeau-niveau-' .. (args.niveau or 'neutre'))
:addClass('plainlinks')
:cssText(args.style) --Provisoire
if args.image then
local imageFormat = res:tag('div')
:addClass('test-bandeau-image')
if mw.ustring.sub(args.image, 1, 1) == '[' then
imageFormat:wikitext(args.image)
else
imageFormat:wikitext(format('[[Fichier:%s|40px|alt=%s|link=]]',
args.image,
args['légende'] or ''))
end
end
res
:tag('p')
:addClass('test-bandeau-texte')
:wikitext(args.texte or erreur(p.erreurArgumentTitre))
return tostring(res)
end
function p.bandeauAvertissement(args)
local icones = {
grave = 'Fairytale no.svg',
['modéré'] = 'Emblem-important.svg',
information = 'Information icon.svg',
['ébauche'] = 'Nuvola apps kedit.svg'
}
local htmlTexte = mw.html.create()
:tag('strong')
:wikitext(args.titre or erreur('Paramètre |titre= introuvable'))
:done()
:tag('br')
:done()
:wikitext(args.texte)
local bandeau = p._bandeau({
classe = 'article',
niveau = args.niveau,
image = args['icône'] or icones[niveau],
texte = tostring(htmlTexte)
})
return bandeau
end
function erreur(texte)
return '<span class="error">Erreur : ' .. texte .. '</span>'
end
function p.ebauche(frame)
--Construction HTML du bandeau d'ebauche
args = frame:getParent().args
local res = mw.html.create('div')
res:addClass('test-bandeau-article test-bandeau-niveau-information plainlinks')
if args.image then
res
:tag('div')
:addClass('test-bandeau-image')
:wikitext(args.image)
end
res
:tag('p')
:addClass('test-bandeau-texte')
:wikitext(args.texte or erreur(p.erreurArgumentTitre))
return tostring(res)
end
return p