Module:Liste de pages-listes

Révision datée du 28 juin 2021 à 17:41 par Kharmitch (discussion | contributions) (Page créée avec « local p = {} local games = { 'Fallout', 'Fallout 2', 'Fallout Tactics', 'Fallout 3', 'Fallout: New Vegas', 'Fallout Shelter', 'Fallout 4', 'Fallout 76', 'Fallout… »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)

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'
}

function p._build(args)
	local mode = args['mode'] or ''
	local subject = args['sujet'] or ''
	
	if subject ~= '' then
		subject = subject .. ' de '
	end
	
	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
		res = mw.html.create( 'div' )
			:addClass( 'avt-game-listpage' )
			:tag( 'div' )
				:addClass( 'avt-game-listpage-title' )
				:wikitext( 'Page-liste par jeu' )
				:done()
			: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