« Module:Biblio » : différence entre les versions
Aller à la navigation
Aller à la recherche
Préparation débugage |
m correction bug : indicationDeLangue |
||
Ligne 6 : | Ligne 6 : | ||
-- ou la table transmise à la fonction par une autre fonction d'un module | -- ou la table transmise à la fonction par une autre fonction d'un module | ||
local function extractArgs ( frame ) | local function extractArgs ( frame ) | ||
return ( frame.getParent and frame:getParent().args ) or frame or { } | |||
end | end | ||
Ligne 40 : | Ligne 39 : | ||
end | end | ||
function Biblio. | function Biblio.libelle ( frame ) | ||
local args = extractArgs ( frame ) | local args = extractArgs ( frame ) | ||
local lib = args ['libellé'] or args [1] or '' | local lib = args ['libellé'] or args [1] or '' | ||
Ligne 52 : | Ligne 51 : | ||
local args = extractArgs ( frame ) | local args = extractArgs ( frame ) | ||
local langue = args.langue | local langue = args.langue | ||
local codeLangue = moduleLangue ( langue ) | local codeLangue = moduleLangue.codeLangue2 ( langue ) | ||
if codeLangue ~= '' and codeLangue ~= 'fr' then | if codeLangue ~= '' and codeLangue ~= 'fr' then | ||
langue = moduleLangue. | langue = moduleLangue.nomLangue ( codeLangue ) | ||
return moduleLangue.indicationDeLangue { langue, codeLangue } | return moduleLangue.indicationDeLangue { langue, codeLangue } | ||
else | else |
Version du 30 juillet 2013 à 19:01
local Biblio = {}
local moduleLangue = require ( 'Module:Langue' )
-- cette simple fonction permet de récupérer les arguement du modèle, -- ou la table transmise à la fonction par une autre fonction d'un module local function extractArgs ( frame )
return ( frame.getParent and frame:getParent().args ) or frame or { }
end
-- fonction abréviation, abréviation discrète -- paramètres : 1 = abréviation, 2 = texte, 3 = langue, abrd = abréviation discrète function Biblio.abr ( frame )
local args = extractArgs ( frame ) if args[2] == nil then return args[1] or -- retoune l'abréviation ou au minimum une chaine vide s'il n'y a pas de texte end
local wikiText = { '<abbr' } if args.abrd then table.insert(wikiText, ' class="abbr"') end table.insert(wikiText, ' title="' .. args[2]) if args[3] then table.insert(wikiText, '" lang="' .. args[3]) end table.insert(wikiText, '">' .. args[1] .. '')
return table.concat (wikiText)
end
function Biblio.spanInitial ( frame )
local args = extractArgs ( frame ) -- préparation pour appel par modèle ou direct.
local id = args.id or
if string.len( id ) == 0 then
id = mw.uri.anchorEncode ( args.id1 .. args.id2 .. args.id3 .. args.id4 .. args.id5 )
end
return ' 0 then
lib = '[' .. lib .. '] '
end
return lib
end
function Biblio.indicationDeLangue ( frame )
local args = extractArgs ( frame ) local langue = args.langue local codeLangue = moduleLangue.codeLangue2 ( langue ) if codeLangue ~= and codeLangue ~= 'fr' then langue = moduleLangue.nomLangue ( codeLangue ) return moduleLangue.indicationDeLangue { langue, codeLangue } else return end
end
function Biblio.responsabilitePrincipale ( frame )
local args = extractArgs ( frame ) local listeRresponsables = { } local nom = ( args ['nom1'] or ) or if nom then return end local directeur = Biblio.abr { 'dir.', 'directeur de publication', abrd = true } local responsable, prenom, lien , precision, resp local i = 1 repeat lien = args [ 'lien' .. i ] or if lien ~= then lien = lien .. '|' end prenom = args [ 'prénom' .. i ] or if prenom ~= then prenom = prenom .. ' ' end precision = args [ 'directeur' .. i ] or resp = args [ 'responsabilité' .. i ] or if precision == then if resp ~= then precision = ' (' .. resp .. ')' end else if resp ~= then precision = ' (' .. directeur .. ' et ' .. resp .. ')' else precision = ' (' .. directeur .. ')' end end responsable = '' .. lien .. prenom .. nom .. '' .. precision table.insert ( listeRresponsables, responsable ) nom = args [ 'nom' .. ( i + 1 ) ] or until nom == if args [ 'et al.' ] == 'oui' then local et_al = " " .. Biblio.abr { "et al.", "et alii (et d’autres)", abrd = true } .. "" return table.concat ( listeRresponsables, ',' ) .. et_al else return mw.text.listToText ( listeRresponsables ) end
end
return Biblio