« Module:Référence » : différence entre les versions

De Les Archives de Vault-Tec
Kharmitch (discussion | contributions)
Page créée avec « local p = {} -------------------------------------- ----- Fonctions communes ----- -------------------------------------- function buildSentence(sentence, lang)… »
 
Kharmitch (discussion | contributions)
mAucun résumé des modifications
Ligne 13 : Ligne 13 :
end
end


function p.getArgs(frame)
function getArgs(frame)
local args = {}
local args = {}



Version du 5 juillet 2021 à 15:00

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

local p = {}

--------------------------------------
-----     Fonctions communes     ----- 
--------------------------------------

function buildSentence(sentence, lang)
	if lang ~= 'fr' then
		return "''" .. sentence .. "''"
	else
		return sentence
	end
end

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

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

function p._buildOneReference(args)
	local ref = ''

	local type = args['type']
	if not type then
		return 'Le paramètre type n\'est pas renseigné.'
	end
	local type = type:lower()

	local name = args['nom']
	if name then
		ref = '<ref name="' .. name .. '">'
	else
		ref = '<ref>'
	end
	
	local lang = args['langue'] or 'fr'

	if type == 'conversation' then
		local game = args['jeu']
		if game then
			game = require( 'Module:Abréviation' ).name(game)
			if game == '' then
				game = 'jeu ?'
			else
				game = "''[[" .. game .. "]]''"
			end
		else
			game = 'jeu ?'
		end

		local character1 = args['personnage1'] or 'personnage1 ?'
		local character2 = args['personnage2'] or 'personnage2 ?'

		ref = ref .. 'Conversation entre ' .. character1 .. ' et ' .. character2 .. ' :'
		ref = ref .. '<br/>'
		
		for i = 1, 6 do
			local sentence = args['phrase' .. i]
			if sentence then
				ref = ref .. '— ' .. buildSentence(sentence, lang) .. '<br/>'
			else
				break
			end
		end

		ref = ref .. 'Extrait du fichier ' .. file .. ', ' .. game
	elseif type == 'document' then
		local quotation = args['citation']
		if quotation then
			ref = ref .. '«&nbsp;' .. buildSentence(quotation, lang) .. '&nbsp;»<br/>'
		end

		local document = args['ouvrage'] or 'ouvrage ?'
		local author = args['auteur'] or 'auteur ?'
		local date = args['date'] or 'date ?'
		local publisher = args['éditeur'] or 'éditeur ?'
		local page = args['page'] or 'page ?'
		
		ref = ref .. author .. '. \'\'' .. document .. '\'\'. ' .. publisher .. ', ' .. date .. '. pp. ' .. page
	end

	ref = ref .. '</ref>'

	return ref
end

function p.buildOneReference(frame)
	local args = getArgs(frame)
	return p._buildOneReference(args)
end

return p