Binding of Isaac: Rebirth Wiki
Advertisement

La documentation pour ce module peut être créée à Module:Test/doc

local p = {}

function p.infobox( f )
	local page = mw.title.new( 'Soufre' )
	local content = page:getContent()
	local templates = mw.text.split( content, '{{' )
	local infobox = {}
	local template
	
	local i = 1
	local exists = false
	repeat
		p.removeSpace( templates[i] )
		if string.find( templates[i], 'Infobox' ) == 1 then
			template = templates[i]
			exists = true
		end
	until not templates[i] or exists
	
	if exists then
		p.remove( template, 'Infobox' )
		p.remove( template, '}}' )
		
		local title = mw.text.split( template, '%s' )
		infobox.title = p.removeSpace( title[1] )
		infobox.param = p.splitParameters( template )
		
		return infobox.title
	else
		return nil
	end
end


function p.splitParameters( text )
	p.removeSpace( text )
	local parameters = mw.text.split( text, '|' )
	table.remove( parameters, 1 )
	
	local Table
	local j = 1
	repeat
		p.removeSpace( parameters[j] )
		local parameter = p.splitParameter( parameters[j] )
		Table[parameter.index] = parameter.value
		j = j + 1
	until not parameters[j]
	
	return Table
end


function p.splitParameter( text )
	local parameter = mw.text.split( text, '=' )
	
	if parameter[3] then
		repeat
			parameter[2] = parameter[2] .. parameter[3]
		until not parameter[3]
	end
	
	return { index = p.removeSpace( parameter[1] ), value = p.removeSpace( parameter[2] ) }
end


function p.remove( text, separator )
	local words = mw.text.split( text, separator )
	local finalText
	
	repeat
		finalText = finalText .. letters[1]
		table.remove( letters, 1 )
	until not words[1]
	
	return finalText
end


function p.removeSpace( text, all )
	local letters = mw.text.split( text, '.' )
	
	if all then
		local i = 1
		repeat
			if letters[i] == '%s' or '\n' then
				table.remove( letters, i )
			else
				i = i + 1
			end
		until letters[i] ~= '%s' or '\n'
	else
		repeat
			if letters[1] == '%s' or '\n' then
				table.remove( letters, 1 )
			end
		until letters[1] ~= '%s' or '\n'
		
		local i = table.maxn( letters )
		repeat
			if letters[i] == '%s' or '\n' then
				table.remove( letters, i )
			end
			i = i - 1
		until letters[i] ~= '%s' or '\n'
	end
	
	local finalText = ''
	repeat
		finalText = finalText .. letters[1]
		table.remove( letters, 1 )
	until not letters[1]
	
	return finalText
end

return p
Advertisement