Module:Liste de pages-listes

De Les Archives de Vault-Tec

La documentation pour ce module peut être créée à Module:Liste de pages-listes/doc

local p = {}

local games = {
	'Fallout',
	'Fallout 2',
	'Fallout Tactics',
	'Fallout 3',
	'Fallout: New Vegas',
	'Fallout Shelter',
	'Fallout 4',
	'Fallout 76',
	'Fallout: Brotherhood of Steel',
	'Van Buren',
	'Project V13',
	'Fallout (série télévisée)'
}

function p._build(args)
	local mode = args['mode'] or ''
	local subject = args['sujet']
	
	if not subject then
		subject = require( 'Module:Outils' ).simpletitle(mw.getCurrentFrame()) .. 's'
	end
	
	subject = subject .. ' de '
	
	local res = mw.html.create( 'ul' )
	
	for k, v in ipairs(games) do
		local pagename = subject .. v
		if mw.title.new( pagename ).exists then
			res	:tag( 'li' )
				:wikitext( "[[" .. pagename .. "|" .. subject .. "''" .. v .. "'']]" )
				:done()
		end
	end
	
	if mode ~= 'liste' then
		local image = args['image']
		if image then
			image = '[[Fichier:' .. image .. '|x100px|center|alt=|link=]]'
		end
		
		res = mw.html.create( 'div' )
			:addClass( 'infobox avt-game-listpage' )
			:tag( 'div' )
				:addClass( 'avt-game-listpage-title' )
				:wikitext( 'Pages-listes par jeu' )
				:done()
			:wikitext(image)
			:node( res:addClass( 'avt-game-listpage-list' ) )
			:done()
	end
	
	return res
end

function p.build(frame)
	local args = {}
	
	local argsParent = frame:getParent().args
	for cle, val in pairs(argsParent) do
		if val then
			args[cle] = mw.text.trim(val)
		end
	end
	
	return p._build(args)
end

return p