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

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
Aucun résumé des modifications
0x010D (discussion | contributions)
Aucun résumé des modifications
Ligne 17 : Ligne 17 :
p.styleStructureTexte = 'display:table-cell; vertical-align:middle;'
p.styleStructureTexte = 'display:table-cell; vertical-align:middle;'
p.erreurArgumentTitre = 'Paramètre « texte » manquant'
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)
function p._bandeau(argsBandeau)
Ligne 93 : Ligne 79 :
end
end


function p.ebauche(frame)
p._ebauche = p['_ébauche']
 
function p._ebauche(args)
--Construction HTML du bandeau d'ebauche
--Construction HTML du bandeau d'ebauche
args = frame:getParent().args
local res = mw.html.create('div')
local res = mw.html.create('div')


Ligne 131 : Ligne 118 :
end
end
   
   
local nomsFonction = {'bandeauAvertissement'}  
local nomsFonction = {'bandeau', 'bandeauAvertissement', 'ébauche'}  
for _, nomFonction in ipairs(nomsFonction) do
for _, nomFonction in ipairs(nomsFonction) do
p[nomFonction] = adaptateur('_' .. nomFonction)
p[nomFonction] = adaptateur('_' .. nomFonction)

Version du 26 juillet 2014 à 13:13

--Ce module implémente le modèle Modèle:Bandeau.

--Standardisation des bandeaux (). --Créer une fonction exportable pour le modè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(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('%s', 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 htmlTexte = mw.html.create() local icones = { grave = 'Fairytale no.svg', ['modéré'] = 'Emblem-important.svg', information = 'Information icon.svg', ['ébauche'] = 'Nuvola apps kedit.svg' }

htmlTexte :tag('strong') :wikitext(args.titre or erreur('Paramètre |titre= introuvable')) :done() :tag('br') :done() :wikitext(args.texte)

local parametres = { classe = 'article', niveau = args.niveau, image = args['icône'] or icones[niveau], texte = tostring(htmlTexte) }

return p._bandeau(parametres) end

function erreur(texte) return 'Erreur : ' .. texte .. '' end

p._ebauche = p['_ébauche']

function p._ebauche(args) --Construction HTML du bandeau d'ebauche 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

--Insertion dans la table p des fonctions appelées par les --modèles à l'aide d'un adaptateur de fonction. function adaptateur(nomFonction) return function (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] = mw.text.trim(val) end end

return p[nomFonction](args) end end

local nomsFonction = {'bandeau', 'bandeauAvertissement', 'ébauche'} for _, nomFonction in ipairs(nomsFonction) do p[nomFonction] = adaptateur('_' .. nomFonction) end

return p