« Module:Bandeau de rubrique » : différence entre les versions

De Les Archives de Vault-Tec
Kharmitch (discussion | contributions)
mAucun résumé des modifications
Kharmitch (discussion | contributions)
mAucun résumé des modifications
Ligne 6 : Ligne 6 :


data = {
data = {
["extrait"] = {
        warning  = false,
        text    = function(args)
        local article = args[1]
        local title = mw.title.new(article)
        local section = args[2]
return 'Extrait de l\'article [[' .. article .. ']], section '
.. section .. '. ([' .. title:fullUrl('action=edit') .. ' modifier])'
.. ' · ([[Aide:Inclusion|Qu\'est ce que c\'est ?]])'
        end
    },
     ["principal"] = {
     ["principal"] = {
         warning  = false,
         warning  = false,
Ligne 37 : Ligne 48 :
         end
         end
     },
     },
     ["extrait"] = {
     ["vide"] = {
         warning  = false,
         warning  = true,
        category = 'Sections vides ou incomplètes',
         text    = function(args)
         text    = function(args)
         local article = args[1]
         local text = 'Cette rubrique est vide, insuffisamment détaillée ou incomplète. ['
        local title = mw.title.new(article)
        .. mw.title:getCurrentTitle():fullUrl('action=edit') .. ' Votre aide] est la bienvenue'
        local section = args[2]
        local todo = args['à faire']
return 'Extrait de l\'article [[' .. article .. ']], section '
        if todo then
.. section .. '. ([' .. title:fullUrl('action=edit') .. ' modifier])'
        text = text .. ' pour ' .. todo
.. ' · ([[Aide:Inclusion|Qu\'est ce que c\'est ?]])'
        end
        return text .. '.'
         end
         end
     }
     },
}
}


Ligne 74 : Ligne 87 :
if category ~= '' then
if category ~= '' then
local game = args['jeu']
if game ~= '' then
if game ~= '' then
game = require( 'Module:Abréviation' ).name(game) or ''
game = require( 'Module:Abréviation' ).name(game) or ''

Version du 7 juillet 2021 à 00:12

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

local p = {}

--------------------------------------------------------
-----     Référentiel des bandeaux de rubrique     -----
--------------------------------------------------------

data = {
	["extrait"] = {
        warning  = false,
        text     = function(args)
        	local article = args[1]
        	local title = mw.title.new(article)
        	local section = args[2]
			return 'Extrait de l\'article [[' .. article .. ']], section '
					.. section .. '. ([' .. title:fullUrl('action=edit') .. ' modifier])'
					.. ' · ([[Aide:Inclusion|Qu\'est ce que c\'est ?]])'
        end
    },
    ["principal"] = {
        warning  = false,
        text     = function(args)
			local link = args[1]
			local display = args['t1'] or link
			
			if not link then return end
			
			text = '[[' .. link .. '|' .. display .. ']]'
			
			local many = false
			for i = 2, 5 do
				local link = args[i]
				local display = args['t' .. i] or link
				if link then
					many = true
					text = text .. ', [[' .. link .. '|' .. display .. ']]'
				else
					break
				end
			end
			
			if many then
				text = 'Articles principaux : ' .. text
			else
				text = 'Article principal : ' .. text
			end
			
			return text
        end
    },
    ["vide"] = {
        warning  = true,
        category = 'Sections vides ou incomplètes',
        text     = function(args)
        	local text = 'Cette rubrique est vide, insuffisamment détaillée ou incomplète. ['
        			.. mw.title:getCurrentTitle():fullUrl('action=edit') .. ' Votre aide] est la bienvenue'
        	local todo = args['à faire']
        	if todo then
        		text = text .. ' pour ' .. todo
        	end
        	return text .. '.'
        end
    },
}

-----------------------------------------------------------

function p.build(frame)
	local args = {}
	args.nom = frame.args.nom
	
	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

function p._build(args)
	local banner = data[args.nom:lower()]
	
	local image = banner.image or ''
	local text = banner.text
	local category = banner.category or ''
	
	if category ~= '' then
		local game = args['jeu']
		if game ~= '' then
			game = require( 'Module:Abréviation' ).name(game) or ''
			if game ~= '' then
				game = ' (' .. game .. ')'
			end
		end
		category = '[[Catégorie:' .. category .. game .. ']]'
	end
	
	if image ~= '' then
		image = mw.html.create( 'span' )
			:addClass( 'avt-section-banner-img' )
			:wikitext( '[[Fichier:' .. image .. '|x30px|link=|alt=]]' )
			:done()
	end
	
	if type(text) == 'function' then
		text = text(args)
	end
	
	local res = mw.html.create( 'div' )
		:addClass( 'avt-section-banner noexcerpt' )
		:wikitext(tostring(image) .. text)
		:done()
	
	return tostring(res) .. category
end

return p