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

De Lagny-sur-Marne Wiki
Aller à la navigation Aller à la recherche
0x010D (discussion | contributions)
nouvelle gestion des styles
0x010D (discussion | contributions)
Aucun résumé des modifications
Ligne 50 : Ligne 50 :
     end   
     end   


     if args.background then -- à supprimer
     if args.style then
        local style = {}
         str = str .. ' style= "' .. table.concat( args.style, '; ' ) .. '"'
        style['background-color'] = args.background
        if args['border-color'] then
            style['border-color'] = args['border-color']
        else
            style['border-color'] = args.background
        end
        if args.color then
            style['color'] = args.color
        end
         str = str .. ' style="' .. formatStyle( style ) .. '"'
     end
     end
     str = str .. '>'
     str = str .. '>'
Ligne 83 : Ligne 73 :
         str = str .. ' style= "' .. table.concat( args.style, '; ' ) .. '"'
         str = str .. ' style= "' .. table.concat( args.style, '; ' ) .. '"'
     end
     end
    str = str .. '>'
      
      
     if args.text then  
     if args.text then  
Ligne 92 : Ligne 83 :


function Infobox:openTable( args )
function Infobox:openTable( args )
     local str = '<table><caption'
     local str = '<table'
 
     if args.class then
     if args.class then
         str = str .. ' class="' .. args.class .. '"'
         str = str .. ' class="' .. args.class .. '"'
Ligne 101 : Ligne 91 :
         str = str .. ' style= "' .. table.concat( args.style, '; ' ) .. '"'
         str = str .. ' style= "' .. table.concat( args.style, '; ' ) .. '"'
     end
     end
    str = str .. '>'
      
      
     if args.text and args.text ~= '' then
     if args.text and args.text ~= '' then
        str = str .. args.text
    str = str .. '<caption'
    else
    if args.styleCaption then
         str = str .. 'Données clés'
            str = str .. ' style= "' .. table.concat( args.styleCaption, '; ' ) .. '"'
        end
         str = str .. '>' .. args.text .. '</caption>'
     end
     end


     self.text = self.text .. str .. '</caption>'
     self.text = self.text .. str
end
end


Ligne 126 : Ligne 119 :
         return
         return
     end
     end
   
     local str = '<tr><th scope="row"'
     local str = '<tr><th scope="row"'
     if args.styleHeader then
     if args.styleHeader then
         str = str .. ' style="' .. args.styleHeader .. '"'
         str = str .. ' style= "' .. table.concat( args.styleHeader, '; ' ) .. '"'
    end
 
    local style = {}
    if args.width then
        style['width'] =  args.width .. 'em'
    end
    if next( style ) then
        str = str .. ' style="' .. formatStyle( style ) .. '"'
     end
     end


Ligne 161 : Ligne 147 :
         return
         return
     end
     end
   
     local str = '<tr><td scope="row" colspan="2"'
     local str = '<tr><td scope="row" colspan="2"'
   
     if args.styleHeader then
     if args.styleHeader then -- ajout de format applicable au label
         str = str .. ' style= "' .. table.concat( args.styleHeader, '; ' ) .. '"'
         str = str .. ' style="' .. args.styleHeader .. '"'
     end
     end
      
      
     self.text = self.text .. str .. '>' .. args.label .. '</td></tr><tr><td scope="row" colspan="2"'
     str = str .. '>' .. args.label .. '</td></tr><tr><td scope="row" colspan="2"'
    str = ''
     if args.styleValue then
     if args.styleValue then -- ajout de format applicable à la valeur
         str = str .. ' style= "' .. table.concat( args.styleValue, '; ' ) .. '"'
         str = str .. ' style="' .. args.styleValue .. '"'
     end
     end
      
      

Version du 19 janvier 2014 à 21:09

local Infobox = {} local i18n = { ['see doc'] = 'Documentation du modèle', ['edit infobox'] = 'Modifier l\'infobox', }

function Infobox:new( args )

   -- Initialisation de l'object
   local object = {
       text = "",
       isPart = false
   }
   setmetatable(object, {
       __index = Infobox,
       __tostring = function( self ) return self:tostring() end
   })
   if args.isPart then
       object.isPart = true
   end
   -- Ouverture de l'élément principal de l'infobox
   if object.isPart then
       return object -- On retourne si on construit seulement un module
   end

local str = '

'
   return object

end

function Infobox:addTitle( args )

   local str = '<p'
   if args.class then
       str = str .. ' class= "' .. args.class ..'"'
   else
   	str = str .. ' class= "entete"'
   end  
   if args.style then
       str = str .. ' style= "' .. table.concat( args.style, '; ' ) .. '"'
   end
   str = str .. '>'
   
   if args.text and args.text ~=  then
       str = str .. args.text
   else
       str = str .. mw.title.getCurrentTitle().text
   end
   
self.text = self.text .. str .. '

'

end

function Infobox:addText( args ) local str = '<p'

   if args.class then
       str = str .. ' class= "' .. args.class ..'"'
   end
   
   if args.style then
       str = str .. ' style= "' .. table.concat( args.style, '; ' ) .. '"'
   end
   str = str .. '>'
   
   if args.text then 
       str = str .. args.text
   end
   
self.text = self.text .. str .. '

'

end

function Infobox:openTable( args )

   local str = '<table'
   if args.class then
       str = str .. ' class="' .. args.class .. '"'
   end
   if args.style then
       str = str .. ' style= "' .. table.concat( args.style, '; ' ) .. '"'
   end
   str = str .. '>'
   
   if args.text and args.text ~=  then
   	str = str .. '<caption'
   	if args.styleCaption then
           str = str .. ' style= "' .. table.concat( args.styleCaption, '; ' ) .. '"'
       end
str = str .. '>' .. args.text .. '' end self.text = self.text .. str end function Infobox:closeTable( args ) self.text = self.text .. ''

end

function Infobox:addMixedRow( args )

   if not args.value or args.value ==  then
   	if args.cat then 
   		self.text = self.text .. -- ajoute catégorie de maintenance
   	end
       return
   end
   if not args.label then
self.text = self.text .. 'Le paramètre label n\'est pas renseigné.'
       return
   end
   
local str = '' .. args.label .. ''
   if args.hidden and args.hidden == 1 then  -- option caché sélectionné: affichage de la valeur sera masqué
self.text = self.text .. ''
   elseif args.weblink and args.weblink ~=  then  -- option lien externe
self.text = self.text .. '[' .. args.weblink .. args.value .. ' ' .. args.value .. ']' else self.text = self.text .. args.value .. '' -- affichage normal de la valeur end end function Infobox:addDoubledRow( args ) if not args.value or args.value == then if args.cat then self.text = self.text .. -- ajoute catégorie de maintenance end return end if not args.label then self.text = self.text .. 'Le paramètre label n\'est pas renseigné!!!'
       return
   end
   
local str = '' .. args.label .. '' .. args.value ..''

end

function Infobox:addImages( args )

   --Get images
   local images = {}
   if not args.images then
       return
   end
   for i,conf in pairs( args.images ) do
       if conf.name and conf.name ~=  then
           table.insert( images, conf )
       end
   end
   if not next( images ) then
       return --Pas d'images
   end
   local imagesCount = table.maxn( images )
   local str = 
   if imagesCount == 2 then
str = '
'
   end
   for i,image in pairs( images ) do
   	-- hack pour enlever puis remettre la catégorie de tracking Wikidata du nom de fichier
   	local t = mw.text.split( image.name, '[[', true )
   	local imagename = t[1]
   	local cat = 
   	if t[2] then
   		cat = '[[' .. t[2]

end

       str = str .. cat ..  'alt=Description de ' if args.legend then str = str .. 'cette image, également commentée ci-après' else str = str .. 'l\'image ' .. image.name end end str = str .. ''
   end
   if imagesCount == 2 then
str = str .. '
'
   end
   if args.legend then
str = str .. '

' .. args.legend .. '

'
   end
   
   self.text = self.text .. str

end

function Infobox:addFooter( args)

   local templatename = args.templatename
   local pagename = mw.title.getCurrentTitle().prefixedText
   local class = args.class
   if not class then
   	class = ""
   end
   local itemlink = 
   local item = args.item
   if item then
   	itemlink = ' - modifier l\'élément Wikidata'

end

text = ''

self.text = self.text .. text end

function Infobox:tostring()

   if self.isPart then
       return self.text
   else
return self.text .. '

'

   end

end

--Create a style property value from an array CSS property = CSS value function formatStyle( args )

   local elems = {}
   for key, val in pairs( args ) do
       table.insert( elems, key .. ':' .. val )
   end
   return table.concat( elems, '; ' )

end

local p = {} function p.new( args )

   return Infobox:new( args )

end function p.test()

   local a = Infobox:new( {} )
   a:addTitle( {} )
   a:addImages( {
       images = {
           {
               name = 'Pellicule.jpg'
           },
           {
               name = 'Pellicule.jpg'
           }
       },
       legend = 'legend'
   } )
   a:openTable( {} )
   a:addMixedRow( {
       label = 'Test',
       value = 'test'
   } )
   a:closeTable( {} )
   return tostring(a)

end return p