« 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 18 : | Ligne 18 : | ||
function p.bandeau(frame) | function p.bandeau(frame) | ||
args = frame:getParent().args | 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 | end | ||
return bandeau(args) | |||
end | end | ||
function | function _bandeau(argsBandeau) | ||
args = argsBandeau | |||
local res = mw.html.create('div') | local res = mw.html.create('div') | ||
res | res | ||
:addClass(argument('class') or p.classStructureBoite) | :addClass(argument('class') or p.classStructureBoite) | ||
:cssText( | :cssText(args.style or '') | ||
if argument('image') then | if argument('image') then | ||
res | res | ||
| Ligne 45 : | Ligne 47 : | ||
:tag('p') | :tag('p') | ||
:addClass('test-bandeau-texte') | :addClass('test-bandeau-texte') | ||
:wikitext( | :wikitext(args.texte or erreur(p.erreurArgumentTitre)) | ||
--Code HTML brut | |||
if args.raw then | |||
return frame:preprocess('<nowiki>' .. tostring(res) .. '</nowiki>') | |||
.. '\n:Éxecution : ' .. os.clock() .. 's' | |||
end | |||
return tostring(res) | return tostring(res) | ||
end | |||
function erreur(texte) | |||
return '<span class="error">Erreur : ' .. texte .. '</span>' | |||
end | end | ||
| Ligne 56 : | Ligne 68 : | ||
res:addClass('test-bandeau-article test-bandeau-niveau-information plainlinks') | res:addClass('test-bandeau-article test-bandeau-niveau-information plainlinks') | ||
if | if args.image then | ||
res | res | ||
:tag('div') | :tag('div') | ||
| Ligne 65 : | Ligne 77 : | ||
:tag('p') | :tag('p') | ||
:addClass('test-bandeau-texte') | :addClass('test-bandeau-texte') | ||
:wikitext( | :wikitext(args.texte or erreur(p.erreurArgumentTitre)) | ||
return tostring(res) | return tostring(res) | ||
end | end | ||
return p | return p | ||
Version du 24 mai 2014 à 23:05
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 = {}
p.classStructureBoite = 'bandeau-simple plainlinks'
p.styleStructureBoite = 'background:#f9f9f9;'
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 bandeau(args)
end
function _bandeau(argsBandeau)
args = argsBandeau
local res = mw.html.create('div')
res
:addClass(argument('class') or p.classStructureBoite)
:cssText(args.style or '')
if argument('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))
--Code HTML brut
if args.raw then
return frame:preprocess('<nowiki>' .. tostring(res) .. '</nowiki>')
.. '\n:Éxecution : ' .. os.clock() .. 's'
end
return tostring(res)
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