local Palette = { }
local function paletteAvecParametre( i, args )
end
function Palette.listePalette( frame )
local args = frame.args
local parentArgs = frame:getParent().args
local wikiTable = { '
\n' }
setmetatable( wikiTable, { __index = table } ) -- permet d'utiliser les fonctions de table comme des méthodes
local palettesVerticales =
local maxPalette = tonumber( args.maxPalette ) or 4
local categoriePaletteInconnue =
local categorieTropDePalette =
local categories = { }
local function _erreur( texte, param, ... )
if param then texte = texte:format( param, ... )
end
local sep = #wikiTable > 1 and '
' or
return sep .. '
' .. texte .. '
\n'
end
local function _pasDePalette()
return _erreur( 'Erreur dans l’utilisation du Modèle:Palette : paramètre obligatoire absent.' )
end
local function _paletteInconnue( i )
categories.paletteInconnue = categoriePaletteInconnue
return _erreur( 'Erreur : il n’existe pas de modèle {{Palette %s}} (aide)', parentArgs[i], parentArgs[i] )
end
local function _paletteAvecParametres( i )
local argsPalette = { }
for n, v in pairs( parentArgs ) do
if not tonumber(n) then
if n:match( ' ' .. i .. '$' ) then
argsPalette[ n:sub(1, n:len() - 1 - tostring(i):len() ) ] = v
elseif not argsPalette[n] then
argsPalette[n] = v
end
end
end
return frame:expandTemplate{ title = 'Palette ' .. mw.text.trim(parentArgs[i]), args = argsPalette }
end
local function _tropDePalettes()
categories.tropDePalette = categorieTropDePalette
return _erreur( 'Erreur dans le Modèle:Palette : trop de palettes (maximum : %s)', maxPalette )
end
local i = 1
while parentArgs[i] and i <= maxPalette do
if parentArgs[i]:match( '%S' ) then
local codePalette = args[i]
local testCodePalette = codePalette:sub(1, 35):lower()
if testCodePalette:match( '^%[%[:modèle:' ) then -- La palette n'existe pas
wikiTable:insert( _paletteInconnue( i ) )
elseif testCodePalette:match( '^palette avec paramètres' ) then -- C'est une palette nécessitant des paramètres nommés
wikiTable:insert( _paletteAvecParametres( i ) )
elseif testCodePalette:match( '^palette verticale avec paramètres' ) then -- C'est une palette verticale nécessitant des paramètres nommés
palettesVerticales = palettesVerticales .. ( _paletteAvecParametres( i ) )
elseif testCodePalette:match( '^palette verticale' ) then -- C'est une palette verticale
palettesVerticales = palettesVerticales .. codePalette:sub( 18 )
else
wikiTable:insert( (codePalette:gsub( '<div class="navbox_group"', '<div' ) ) )
-- une ancre ^ pourra être ajoutée pour gagner en performance lorsque le modèle palette ne commencera plus par
end
end
i = i + 1
end
if i == 1 then
wikiTable:insert( _pasDePalette() )
elseif i > maxPalette and parentArgs[i] and parentArgs[i] ~= then
wikiTable:insert( _tropDePalettes() )
end
if #wikiTable == 1 then
wikiTable[1] = palettesVerticales
else
wikiTable:insert( '
' .. palettesVerticales )
end
if mw.title.getCurrentTitle().namespace == 0 then
for i, v in pairs( categories ) do
wikiTable:insert( v )
end
end
return wikiTable:concat()
end
return Palette