« Module:Extrait » : différence entre les versions

De Les Archives de Vault-Tec
Kharmitch (discussion | contributions)
Premier jet du module Extrait
 
Kharmitch (discussion | contributions)
mAucun résumé des modifications
 
(2 versions intermédiaires par le même utilisateur non affichées)
Ligne 5 : Ligne 5 :
--------------------------------------
--------------------------------------


local errorText = "[[Catégorie:Erreur d'inclusion d'un article]]<Erreur module> Impossible de générer l'extrait."
local errorText = "[[Catégorie:Page avec une erreur d'inclusion]]<Erreur module> Impossible de générer l'extrait."


function getArgs(frame)
function getArgs(frame)
Ligne 53 : Ligne 53 :
end
end
return text
return '\n' .. mw.text.trim(text)
end
end


return p
return p

Dernière version du 17 septembre 2022 à 00:28

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

local p = {}

--------------------------------------
-----     Fonctions internes     ----- 
--------------------------------------

local errorText = "[[Catégorie:Page avec une erreur d'inclusion]]<Erreur module> Impossible de générer l'extrait."

function getArgs(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 args
end

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

function p.build(frame)
	local args = getArgs(frame)
	
	local article = args[1]
	if not article then
		return "<Erreur module> Le paramètre article doit être renseigné."
	end
	
	if not mw.title.new(article).exists then
		return errorText .. " L'article à inclure n'existe pas."
	end
	
	local text, textType
	local section = args['section']
	local heading = args['rubrique']
	
	if section then
		textType = 'section'
		text = frame:callParserFunction{ name = '#lst', args = { article, section } }
	elseif heading then
		textType = 'rubrique'
		text = frame:callParserFunction{ name = '#lsth', args = { article, heading } }
	else
		text = frame:callParserFunction{ name = '#lsth', args = { article } }
	end
	
	if #text == 0 then
		return errorText .. " La " .. textType .. " n'existe pas."
	end
	
	return '\n' .. mw.text.trim(text)
end

return p