« Module:Référence » : différence entre les versions
mAucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 28 : | Ligne 28 : | ||
-------------------------------------- | -------------------------------------- | ||
function p. | function p.buildOneReference(frame) | ||
local | 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 | ||
attributes['name'] = name | |||
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 ?' | ||
content = content .. 'Conversation entre ' .. character1 .. ' et ' .. character2 .. ' :' | |||
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 | ||
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 ?' | ||
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 | ||
content = content .. '« ' .. formatSentence(quotation, lang) .. ' »<br/>' | |||
end | end | ||
Ligne 89 : | Ligne 95 : | ||
local page = args['page'] or 'page ?' | local page = args['page'] or 'page ?' | ||
content = content .. author .. '. \'\'' .. document .. '\'\'. ' .. publisher .. ', ' .. date .. '. pp. ' .. page | |||
end | end | ||
return frame:extensionTag( 'ref', content, attributes ) | |||
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 .. '« ' .. formatSentence(quotation, lang) .. ' »<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