« Module:Biblio » : différence entre les versions

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
Préparation débugage (bis)
0x010D (discussion | contributions)
indicationDeLangue : simplification, responsabilitePrincipale : correction boucle infinie
Ligne 1 : Ligne 1 :
local Biblio = {}
local Biblio = {}


local moduleLangue = require ( 'Module:Langue' )
local Langue = require ( 'Module:Langue' )


-- cette simple fonction permet de récupérer les arguement du modèle,  
-- cette simple fonction permet de récupérer les arguement du modèle,  
Ligne 51 : Ligne 51 :
function Biblio.indicationDeLangue ( frame )
function Biblio.indicationDeLangue ( frame )
     local args = extractArgs ( frame )
     local args = extractArgs ( frame )
    local langue = args.langue
     local codeLangue = Langue.codeLangue2 ( args.langue )
     local codeLangue = moduleLangue.codeLangue2 ( langue )
     if codeLangue ~= '' and codeLangue ~= 'fr' then
     if codeLangue ~= '' and codeLangue ~= 'fr' then
        langue = moduleLangue.nomLangue ( codeLangue )
         return Langue.indicationDeLangue { '', codeLangue }
         return moduleLangue.indicationDeLangue { langue, codeLangue }
     else
     else
         return ''
         return ''
Ligne 63 : Ligne 61 :
function Biblio.responsabilitePrincipale ( frame )
function Biblio.responsabilitePrincipale ( frame )
     local args = extractArgs ( frame )
     local args = extractArgs ( frame )
    local listeRresponsables = { }
     local nom = args ['nom1'] or ''
     local nom = ( args ['nom1'] or '' ) or ''
      
      
     if nom then
     if nom == '' then
         return ''
         return ''
     end
     end
      
      
    local listeRresponsables = { }
     local directeur = Biblio.abr { 'dir.', 'directeur de publication', abrd = true }
     local directeur = Biblio.abr { 'dir.', 'directeur de publication', abrd = true }
     local responsable, prenom, lien , precision, resp
     local responsable, prenom, lien , precision, resp
     local i = 1
     local i = 1
     repeat  
     repeat  
        lien = args [ 'lien' .. i ] or ''
        if lien ~= '' then lien = lien .. '|' end
         prenom = args [ 'prénom' .. i ] or ''
         prenom = args [ 'prénom' .. i ] or ''
         if prenom ~= '' then prenom = prenom .. ' ' end
         if prenom ~= '' then prenom = prenom .. ' '  
        end
          
          
         precision = args [ 'directeur' .. i ] or ''
         precision = args [ 'directeur' .. i ] or ''
Ligne 93 : Ligne 90 :
         end
         end
          
          
         responsable = '[[' .. lien .. prenom .. nom .. ']]' .. precision
         lien = args [ 'lien' .. i ] or ''
        if lien ~= '' then
            responsable = '[[' .. lien .. '|' .. prenom .. nom .. ']]' .. precision
        else
            responsable = prenom .. nom .. precision
        end
       
         table.insert ( listeRresponsables, responsable )
         table.insert ( listeRresponsables, responsable )
          
          
         nom = args [ 'nom' .. ( i + 1 ) ] or ''
        i = i + 1
         nom = args [ 'nom' .. i ] or ''
          
          
     until nom == ''
     until nom == ''

Version du 30 juillet 2013 à 20:16

local Biblio = {}

local Langue = 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 { }
   return frame.args or frame or { } -- renvoie les arguments transmis par invoke et non par le modèle, pour tester avant de créer les modèle.

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 codeLangue = Langue.codeLangue2 (  args.langue )
   if codeLangue ~=  and codeLangue ~= 'fr' then
       return Langue.indicationDeLangue { , codeLangue }
   else
       return 
   end

end

function Biblio.responsabilitePrincipale ( frame )

   local args = extractArgs ( frame )
   local nom = args ['nom1'] or 
   
   if nom ==  then
       return 
   end
   
   local listeRresponsables = { }
   local directeur = Biblio.abr { 'dir.', 'directeur de publication', abrd = true }
   local responsable, prenom, lien , precision, resp
   local i = 1
   repeat 
       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
       
       lien = args [ 'lien' .. i ] or 
       if lien ~=  then 
           responsable = '' .. prenom .. nom .. '' .. precision
       else
           responsable = prenom .. nom .. precision
       end
       
       table.insert ( listeRresponsables, responsable )
       
       i = i + 1
       nom = args [ 'nom' .. i ] 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