Aller au contenu

Module:HhakD

La bibliothèque libre.
Documentation du module [voir] [modifier] [purger]
La documentation de ce module Scribunto écrit en Lua est incluse depuis sa sous-page de documentation.
local szCode = ''

local function sc_en_span( sz )
-- Remplace {{sc|...}} ou {{Sc|...}} par <span petite capitales>...</span>
-- Réduit la wikiinflation des modèles dans les modèles
-- Hypothèse
-->> aucun modèle n'est à l'intérieur de {{sc|...}}.

  local a = mw.text.split( sz, '{{[Ss]c|' )
  local b = nil
  local c = {}
  for i, chaine in pairs(a) do
    if mw.ustring.find( chaine, '}}', 1, true ) ~= nil then
      b = mw.text.split( chaine, '}}', true )
      table.insert( c, table.concat( b, '</span>' ) )
    else
      table.insert( c, chaine )
    end
  end
  
  return table.concat( c, '<span style="font-variant:small-caps;" class=sc>' )
end

local function Construire( frame )
-- Hypothèses 
-- >> Les paramètres dida, aligne, retrait, mt et mb existent et peuvent être vides.

  -- Valeurs par défaut
  local szDida = ''
  local szAligne = 'c'
  local szRetrait = '2em'
  local szMt = '0.5em'
  local szMb = '0.5em'
  
  if frame.args.dida ~= '' then szDida = frame.args.dida end
  if frame.args.aligne ~= '' then szAligne = frame.args.aligne end
  if frame.args.retrait ~= '' then szRetrait = frame.args.retrait end
  if frame.args.mt ~= '' then szMt = frame.args.mt end
  if frame.args.mb ~= '' then szMb = frame.args.mb end
  
  szDida = sc_en_span( szDida )
  
  szCode = ''
  
  -- À gauche
  if szAligne == 'g' then
    szCode = szCode .. '<div style="text-align:left; font-size:90%; '
    szCode = szCode .. 'margin:0.5em 0 0.5em ' .. szRetrait .. ';'
    szCode = szCode .. '">' .. szDida .. '</div>'
  end

    -- Au centre
  if szAligne == 'c' then
    szCode = szCode .. '<div style="text-align:center; font-size:90%; '
    szCode = szCode .. 'margin:' .. szMt .. ' 0 ' .. szMb .. ' 0;'
    szCode = szCode .. '">' .. szDida .. '</div>'
  end

  -- À droite
  if szAligne == 'd' then
    szCode = szCode .. '<div style="text-align:right; font-size:90%; '
    szCode = szCode .. 'margin:0.5em ' .. szRetrait .. ' 0.5em 0;'
    szCode = szCode .. '">' .. szDida .. '</div>'
  end
  
  -- flottant
  if szAligne == 'f' then
    szCode = szCode .. '<span style="font-size:90%;">' .. szDida .. '</span>'
  end
  
  -- Messages au contributeur
  if frame.args.dida == '' then
    szCode = '<span style="color:red; font-size:200%;">La didascalie est absente.</span>'
  end
  if szAligne ~= 'g' and szAligne ~= 'c' and szAligne ~= 'd' and szAligne ~= 'f' then
    szCode = '<span style="color:red; font-size:200%;">Le code d’alignement est inconnu. Indiquer g, c, d, f ou (rien).</span>'
  end

  return szCode
end

------------
------------
local p = {}

function p.Construire( frame )
  return Construire( frame )
end

return p