« Module:Bandeau » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 20 : | Ligne 20 : | ||
function p.bandeau(frame) | function p.bandeau(frame) | ||
args = frame:getParent().args | |||
--Code HTML brut | |||
if args.raw then | |||
res = frame:preprocess('<nowiki>' .. p._bandeau() .. '</nowiki>') .. '\n:Éxecution : ' .. os.clock() .. 's' | |||
return res | |||
else | else | ||
return p._bandeau() | return p._bandeau() | ||
| Ligne 32 : | Ligne 32 : | ||
function p._bandeau() | function p._bandeau() | ||
--Construction HTML du bandeau | |||
local res = mw.html.create('div') | |||
res | |||
:addClass(argument('class') or p.classStructureBoite) | |||
--:cssText(args.style)--argument('style') | |||
if argument('image') then | |||
res | |||
:tag('div') | :tag('div') | ||
:addClass('test-bandeau-image') | |||
:wikitext(args.image) | |||
end | |||
res | |||
:tag('p') | |||
:addClass('test-bandeau-texte') | |||
:wikitext(argument('texte') or erreur(p.erreurArgumentTitre)) | |||
return tostring(res) | return tostring(res) | ||
Version du 20 février 2014 à 13:23
--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 TableBuilder = require('Module:TableBuilder')
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)
args = frame:getParent().args
--Code HTML brut
if args.raw then
res = frame:preprocess('' .. p._bandeau() .. '') .. '\n:Éxecution : ' .. os.clock() .. 's'
return res
else return p._bandeau() end end
function p._bandeau()
--Construction HTML du bandeau
local res = mw.html.create('div')
res
:addClass(argument('class') or p.classStructureBoite)
--:cssText(args.style)--argument('style')
if argument('image') then
res
:tag('div')
:addClass('test-bandeau-image')
:wikitext(args.image)
end
res
:tag('p')
:addClass('test-bandeau-texte')
:wikitext(argument('texte') or erreur(p.erreurArgumentTitre))
return tostring(res) end
function p.ebauche(frame) args = frame:getParent().args tab = TableBuilder.new()
--Construction HTML du bandeau structureHtml('div', 'test-bandeau-article test-bandeau-niveau-information plainlinks') if argument('image') then structureHtml('div', 'test-bandeau-image', nil, args.image) structureHtmlFin('div') end structureHtml('p', 'test-bandeau-texte', nil, argument('texte') or erreur(p.erreurArgumentTitre)) structureHtmlFin('p') structureHtmlFin('div')
return tab.concat() end
function argument(parametre)
--Test de paramètre vide interprété par Lua
if args[parametre] == then return nil end
return args[parametre]
end
function erreur(texte) return 'Erreur : ' .. texte .. '' end
function structureHtml(balise, class, style, contenu) tab.insert('<') .insert(balise)
if class then tab.insert(' class="') .insert(class) .insert('"') end
if style then tab.insert(' style="') .insert(style) .insert('"') end
tab.insert('>') .insert(contenu) end
function structureHtmlFin(balise) tab.minsert('</', balise, '>') end
return p