Módulo:Caixa de navegação

Fonte: Enciclopédia de conhecimento da Igreja de Deus
Revisão em 00h41min de 14 de maio de 2024 por Jaewoo (discussão | contribs) (Criou a página com "local Palette = { } function Palette.listaCaixa( frame ) local args = frame.args local parentArgs = frame:getParent().args local wikiTable = { '<div class="navbox-container" style="clear:both;">\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 = '[[Catego...")
(dif) ← Revisão anterior | Revisão atual (dif) | Revisão seguinte → (dif)
Saltar para a navegação Saltar para a pesquisa

A documentação para este módulo pode ser criada na página Módulo:Caixa de navegação/doc

local Palette = { }
function Palette.listaCaixa( frame )
				local args = frame.args
				local parentArgs = frame:getParent().args
			
				local wikiTable = { '<div class="navbox-container" style="clear:both;">\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 = '[[Categoria:!Predefinição Caixa de navegação - Caixa desconhecida]]'
				local categorieTropDePalette = '[[Categoria:!Predefinição Caixa de navegação - Página com demasiadas caixas]]'
				local categoriePaletteEnDouble = '[[Categoria:!Predefinição Caixa de navegação - Caixa informada em duplicado]]'
			
				local categories = { }
			
				local function _erreur( texte, param, ... )
								if param then texte = texte:format( param, ... )
								end
								local sep = #wikiTable > 1 and '<hr>' or ''
								return sep .. '<p><strong class="error" style="padding-left:.5em;">' .. texte .. '</strong></p>\n'
				end
				local function _pasDePalette()
								return _erreur( 'Erro na utilização de [[Predefinição:Caixa de navegação]] : parâmetro obrigatório em falta.' )
				end
			
				local function _paletteInconnue( i )
								categories.paletteInconnue = categoriePaletteInconnue
								local nomPalette = mw.text.trim( parentArgs[i] )
								return _erreur( 'Erro : não existe a predefinição de caixa de navegação {{[[Predefinição:%s|%s]]}} [[Ajuda:Caixa de informação|(ajuda)]]', nomPalette, nomPalette )
				end
				local function _paletteEnDouble ( i )
								categories.paletteEnDouble = categoriePaletteEnDouble
								return "" -- inutile d'afficher une erreur visible pour ce cas puisque la mise en page n'est pas cassée
				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 n == 'nocat' .. i then
																				argsPalette.nocat = v
																elseif not argsPalette[n] and n ~= 'stylecorps' then
																				argsPalette[n] = v                   
																end
												end
								end
								return frame:expandTemplate{ title = 'Caixa de navegação ' .. mw.text.trim(parentArgs[i]), args = argsPalette }
				end
			
				local function _tropDePalettes()
								categories.tropDePalette = categorieTropDePalette
								return _erreur( 'Erro na [[Predefinição:Caixa de navegação]] : demasiadas caixas (máximo : %s)', maxPalette )
				end
			
			
				local boite = parentArgs['titre boîte déroulante'] or parentArgs['titre boite déroulante']
				if boite then
								wikiTable[1] = '<div class="NavFrame navbox-container" style="clear:both;" >\n'
												.. '<div class="NavHead" style="text-align:center; height:1.6em; background-color:'
												.. ( parentArgs.couleurFondT or '#CCF' )
												.. '; color:' .. ( parentArgs.couleurTexteT or 'black' ) .. ';">'
												.. boite
												.. '</div>\n<div class="NavContent" style="margin-top:2px;">\n'
				end
				local i = 1
				local palettesValides = {}
			
				while parentArgs[i] and i <= maxPalette  do
								if parentArgs[i]:match( '%S' ) then
												for _, j in ipairs( palettesValides ) do
																if args[i] == args[j] and not args[i]:match('^caixa de navegação ') then
																				wikiTable:insert ( _paletteEnDouble(i))
																end
												end
												table.insert( palettesValides, i )
												if parentArgs[i]:match( '<table class="navbox' ) or parentArgs[i]:match( '{| ?class="navbox' ) then
																wikiTable:insert( parentArgs[i] )
												else
																local codePalette = args[i] 
																local testCodePalette = codePalette:lower()
																if testCodePalette:match( '^%[%[:predefinição:' ) then                  -- La palette n'existe pas
																				wikiTable:insert( _paletteInconnue( i ) )
																				table.remove( palettesValides )
																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%-container"', '<div' ) ) )
																end
												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
								if boite then
												wikiTable:insert( '</div>' )
								end
								wikiTable:insert( '</div>' .. 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