Module:PageTitre/Bac à sable
Apparence
La documentation pour ce module peut être créée à Module:PageTitre/Bac à sable/Documentation
-- Pages de test :
--Page:Maupassant - La maison Tellier - Ollendorff, 1899.djvu/289
--Page:Test affichage.djvu/29
--Utilisateur:Cantons-de-l'Est/Test/PageTitre/0
-- Le nombre de lignes peut être augmenté.
local nNombreLignes = 40
local p = {}
local args = {}
local szMsg = ''
local szCode = ''
local szParam = ''
local nNombreParam = 3 * nNombreLignes
local util = require("Module:StyleM")
local pdf = {}
pdf['a4w'] = 595
pdf['a4h'] = 842
pdf['a5w'] = 500 --au lieu de 420 car 500px est comprimée pour loger dans 420px
pdf['a5h'] = 700 --au lieu de 595 avec ratio 500/420
pdf['letterw'] = 612
pdf['letterh'] = 792
function addStyle(str, key)
if args[key] ~= nil then
str = str .. util.toCss(key .. ':' .. args[key])
end
return str
end
function prepPdfRule(formatPdf)
szCode = szCode .. '<div style=" position:relative; max-width:500px; '
.. 'min-height:' .. pdf[formatPdf .. 'h'] .. 'px; margin:auto>'
end
function getOuvrirDivTitre(style)
szCode = szCode .. '<div ' .. style .. '">'
end
function getFermerDivTitre()
szCode = szCode .. '</div>'
end
function buildPdfRule(key)
local str = ''
local szF = mw.ustring.lower(args[key])
--szF = 'letter'
str = '</div><div style="position:absolute; border-left: 3px dotted blue;'
.. 'border-top: 3px dotted blue; width:100%; '
.. 'max-width:' .. pdf[szF .. 'w'] .. 'px;'
.. 'height:' .. pdf[szF .. 'h'] .. 'px;top:0;'
.. 'left:0);">'
.. '<div style="background-color: transparent; line-height:1; '
.. 'color:blue">' .. mw.ustring.upper(szF) .. '</div></div>'
szCode = szCode .. str
end
function getLigne(sz0, sz1, sz2)
-- Si l'unité de l'espacement vertical a été indiquée, utiliser cette unité
-- sinon ajouter em, l’unité par défaut
---------------------------------------------------------------------------
if tonumber(sz0) ~= nil then
sz0 = sz0 .. 'em'
end
-- Taille si paramètre 3 est numérique ou numérique se terminant par %
-- sinon traiter comme un style wsCss
---------------------------------------------------------------------------
if tonumber(sz2) == nil then
if tonumber(mw.ustring.sub(sz2,1,mw.ustring.len( sz2 ) -1)) == nil then
sz2 = util.toCss(sz2)
end
else
sz2 = 'font-size:' .. sz2 .. '%'
end
-- Centrer le texte si align non spécifié dans wsCss
if not mw.ustring.find(sz2, 'text%-align') then
sz2 = 'text-align:center;' .. sz2
end
-- Espacement entre les lignes de la page-titre si requis
if sz0 ~= '' then
szCode = szCode .. '<div style="padding-bottom:' .. sz0
.. ';"> </div>'
end
-- Contenu html de la page-titre, ligne par ligne
szCode = szCode .. '<div style="clear:both;' .. sz2 .. '";>'
.. sz1 ..'</div>'
end
function p.Construire( frame )
--------------------------------
-- Noter les paramètres sans nom
--------------------------------
if frame:getParent().args[1] ~= nil then
args = frame:getParent().args
else
args = frame.args
end
local aParamSansNom = {}
local szInfo = ''
local nCnt
for i, v in ipairs(args) do
if i > nNombreParam then break end -- le max. de ligne est atteint
aParamSansNom[i] = mw.text.trim(v)
szInfo = szInfo .. 'Paramètre ' .. i .. ' : '
.. aParamSansNom[i] .. '<br>\n'
if i % 3 == 0 then
szInfo = szInfo .. '<br>\n'
end
end
local nCnt = #aParamSansNom
if nCnt % 3 ~= 0 then
szMsg = '<span style="font-size:200%; color:red;">'
.. 'Prière de saisir 3 paramètres par ligne.</span>'
.. '<br>\n' .. szInfo
end
------------------------------
-- Recueillir les paramètres nommées
------------------------------
local affPdf = false
if args['pdf'] ~= nil then
if not mw.title.getCurrentTitle():inNamespaces( 'Livre', '' )
and (pdf[mw.ustring.lower(args['pdf'] .. 'w')] ~= nil) then
affPdf = true
end
end
if affPdf then prepPdfRule(args['pdf']) end
local gStyle = ''
if args['titre'] then gStyle = 'class="titre" ' end
gStyle = gStyle .. 'style="position:relative; ' -- break-after:always;'
.. 'max-width:500px; margin:0 auto;'
gStyle = gStyle .. util.toCss(args['style'])
gStyle = addStyle(gStyle, 'fs')
gStyle = addStyle(gStyle, 'ff')
gStyle = addStyle(gStyle, 'bp')
------------------------------
-- Créer le code HTML/Wikicode
------------------------------
getOuvrirDivTitre(gStyle)
-- Pour chaque trio définissant une ligne, ajouter le code pertinent
--------------------------------------------------------------------
for n = 1, nCnt, 3 do
getLigne(aParamSansNom[n], aParamSansNom[n + 1], aParamSansNom[n + 2])
end
if affPdf then buildPdfRule('pdf') end
getFermerDivTitre()
if string.len( szMsg ) ~= 0 then
szCode = szMsg
end
return szCode
end
return p