Différences entre les versions de « Module:Présentation »

De Wiki Seb35
Aller à la navigation Aller à la recherche
(retrait des tests)
Ligne 6 : Ligne 6 :


function presentation.total( frame )
function presentation.total( frame )
     return table.getn( presentation._expandSequence( mw.title.getCurrentTitle() ) )
     local sequence = presentation._expandSequence( mw.title.getCurrentTitle() )
end
     return table.getn( sequence )
 
function presentation.test( frame )
     return tonumber(mw.title.getCurrentTitle().subpageText)
end
 
function presentation.test2( frame )
    return tonumber(mw.title.getCurrentTitle().subpageText)+1
end
 
function presentation.test3( frame )
    return mw.title.getCurrentTitle().basePageTitle:subPageTitle( tostring(tonumber(mw.title.getCurrentTitle().subpageText)+1) )
end
 
function presentation.test4( frame )
    return mw.title.getCurrentTitle().basePageTitle:subPageTitle( tostring(tonumber(mw.title.getCurrentTitle().subpageText)+1) ).exists
end
end


function presentation.current( frame )
function presentation.current( frame )
     for i,v in pairs( presentation._expandSequence( mw.title.getCurrentTitle() ) ) do
     local sequence = presentation._expandSequence( mw.title.getCurrentTitle() )
    for i,v in pairs( sequence ) do
         if v == mw.title.getCurrentTitle().fullText then
         if v == mw.title.getCurrentTitle().fullText then
             return i
             return i

Version du 10 avril 2015 à 17:56

--[[

]]

local presentation = {}

function presentation.total( frame )

   local sequence = presentation._expandSequence( mw.title.getCurrentTitle() )
   return table.getn( sequence )

end

function presentation.current( frame )

   local sequence = presentation._expandSequence( mw.title.getCurrentTitle() )
   for i,v in pairs( sequence ) do
       if v == mw.title.getCurrentTitle().fullText then
           return i
       end
   end

end

function presentation.next( frame )

   local sequence = presentation._expandSequence( mw.title.getCurrentTitle() )
   for i,v in pairs( sequence ) do
       if v == mw.title.getCurrentTitle().fullText then
           return sequence[i+1]
       end
   end

end

function presentation.previous( frame )

   local sequence = presentation._expandSequence( mw.title.getCurrentTitle() )
   for i,v in pairs( sequence ) do
       if v == mw.title.getCurrentTitle().fullText then
           return sequence[i-1]
       end
   end

end

function presentation._expandSequence( title )

   local list = {};
   title = title.rootPageTitle;
   while true do
       if title:subPageTitle( '0' ).exists then
           title = title:subPageTitle( '0' )
           list[table.getn(list)+1] = title.fullText
       elseif title:subPageTitle( '1' ).exists then
           title = title:subPageTitle( '1' )
           list[table.getn(list)+1] = title.fullText
       elseif title.basePageTitle:subPageTitle( tostring(tonumber(title.subpageText)+1) ).exists then
           title = title.basePageTitle:subPageTitle( tostring(tonumber(title.subpageText)+1) )
           list[table.getn(list)+1] = title.fullText
       elseif title.baseText ~= title.rootText then
           title = title.basePageTitle
       else
           break
       end
   end
   return list

end

return presentation