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

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


function p._buildOneReference(args)
function p.buildOneReference(frame)
local ref = ''
local args = getArgs(frame)
 
local type = args['type']
local type = args['type']
if not type then
if not type then
Ligne 36 : Ligne 36 :
end
end
local type = type:lower()
local type = type:lower()
local attributes = {}


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


Ligne 62 : Ligne 68 :
local character2 = args['personnage2'] or 'personnage2 ?'
local character2 = args['personnage2'] or 'personnage2 ?'


ref = ref .. 'Conversation entre ' .. character1 .. ' et ' .. character2 .. ' :'
content = content .. 'Conversation entre ' .. character1 .. ' et ' .. character2 .. ' :'
ref = ref .. '<br/>'
content = content .. '<br/>'
for i = 1, 6 do
for i = 1, 6 do
local sentence = args['phrase' .. i]
local sentence = args['phrase' .. i]
if sentence then
if sentence then
ref = ref .. '— ' .. formatSentence(sentence, lang) .. '<br/>'
content = content .. '— ' .. formatSentence(sentence, lang) .. '<br/>'
else
else
break
break
Ligne 76 : Ligne 82 :
local file = args['fichier'] or 'fichier ?'
local file = args['fichier'] or 'fichier ?'


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


Ligne 89 : Ligne 95 :
local page = args['page'] or 'page ?'
local page = args['page'] or 'page ?'
ref = ref .. author .. '. \'\'' .. document .. '\'\'. ' .. publisher .. ', ' .. date .. '. pp. ' .. page
content = content .. author .. '. \'\'' .. document .. '\'\'. ' .. publisher .. ', ' .. date .. '. pp. ' .. page
end
end


ref = ref .. '</ref>'
return frame:extensionTag( 'ref', content, attributes )
 
return ref
end
 
function p.buildOneReference(frame)
local args = getArgs(frame)
return p._buildOneReference(args)
end
end


return p
return p

Version du 5 juillet 2021 à 15:23

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

local p = {}

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

function formatSentence(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(frame)
	local args = getArgs(frame)
	
	local type = args['type']
	if not type then
		return 'Le paramètre type n\'est pas renseigné.'
	end
	local type = type:lower()
	
	local attributes = {}

	local name = args['nom']
	if name then
		attributes['name'] = name
	end
	
	local group = args['groupe']
	if group then
		attributes['group'] = group
	end
	
	local content = ''
	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 ?'

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

		content = content .. 'Extrait du fichier ' .. file .. ', ' .. game
	elseif type == 'document' then
		local quotation = args['citation']
		if quotation then
			content = content .. '«&nbsp;' .. formatSentence(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 ?'
		
		content = content .. author .. '. \'\'' .. document .. '\'\'. ' .. publisher .. ', ' .. date .. '. pp. ' .. page
	end

	return frame:extensionTag( 'ref', content, attributes )
end

return p