Différences entre les versions de « Module:Fo »
De Commission Historique
m |
m Balise : Révoqué |
||
Ligne 59 : | Ligne 59 : | ||
local ref = frame.args['ref']:gsub('(.-)%s*$','%1') | local ref = frame.args['ref']:gsub('(.-)%s*$','%1') | ||
local precision = frame.args['precision']:gsub("[\n\r]","") | local precision = frame.args['precision']:gsub("[\n\r]","") | ||
local compat = frame.args['compat']:gsub("[\n\r]","") | |||
if #ref < 2 then | if #ref < 2 then | ||
return '' | return '' | ||
else | else | ||
return modelRef(ref,precision,frame.args['field']) | return modelRef(ref,precision,frame.args['field'],compat) | ||
end | end | ||
end | end | ||
function modelRef(ref,precision,field) | function modelRef(ref,precision,field,compat) | ||
local content, pr = "", "" | local content, pr = "", "" | ||
r = mw.text.truncate(ref,-8,'') | r = mw.text.truncate(ref,-8,'') | ||
if bbib[r] then | if bbib[r] then | ||
Ligne 79 : | Ligne 80 : | ||
end | end | ||
if #precision > 1 then | if #precision > 1 then | ||
precision = ". " .. precision | |||
end | end | ||
content = content .. model[b["ItemType"]](b) | content = content .. model[b["ItemType"]](b) | ||
Ligne 87 : | Ligne 88 : | ||
local name = mw.hash.hashValue( 'sha1', content .. pr ) | local name = mw.hash.hashValue( 'sha1', content .. pr ) | ||
if field ~= "Publication" and field ~= "Reference" then | if field ~= "Publication" and field ~= "Reference" then | ||
return '<ref name="' .. name .. '">' .. content .. | if #compat < 1 then | ||
return '<ref name="' .. name .. '">' .. content .. precision .. '</ref>' | |||
else | |||
return '{{#tag:ref|' .. content .. precision .. '|name=' .. name .. '}}' | |||
end | |||
else | else | ||
return "*" .. content .. | return "*" .. content .. precision .. "\n" | ||
end | end | ||
end | end |
Version du 25 mars 2022 à 15:32
La documentation pour ce module peut être créée à Module:Fo/doc
local p = {}
local bbib=mw.loadData( 'module:Fo/data' )
local model = {
["book"] = function (b)
return b.TitleItem .. ". " .. b.Place .. " : " .. b.Publisher .. ", " .. mw.text.truncate(b.PublicationYear,4,'')
end,
["bookSection"] = function (b)
return b.TitleItem .. ". In:" .. b.PublicationTitle .. ", " .. b.Editor .. ", " .. b.Pages .. ". " .. b.Place .. " : " .. b.Publisher .. ", " .. mw.text.truncate(b.PublicationYear,4,'')
end,
["journalArticle"] = function (b)
return b.TitleItem .. ". " .. b.PublicationTitle .. " " .. b.Volume .. " (" .. mw.text.truncate(b.PublicationYear,4,'') .. ") : " .. b.Pages
end,
["thesis"] = function (b)
return b.TitleItem .. ". " .. b.Type .. ". " .. b.Place .. ", " .. mw.text.truncate(b.PublicationYear,4,'')
end,
["magazineArticle"] = function (b)
return b.TitleItem .. ". " .. b.PublicationTitle .. ". " .. b.Date
end,
["patent"] = function (b)
return b.TitleItem .. ". " .. b.IssuingAuthority .. " " .. b.Number .. ", " .. "{{int:Template-depose_le}} " .. b.FilingDate .. " {{int:Template-et_accorde_le}} " .. b.Date
end,
["encyclopediaArticle"] = function (b)
return b.TitleItem .. ". In:" .. b.PublicationTitle .. ". " .. b.Publisher .. ", " .. mw.text.truncate(b.PublicationYear,4,'') .. ". " .. b.Url
end,
["report"] = function (b)
return b.TitleItem .. ". " .. b.ItemType .. " " .. b.Number .. ". " .. b.Place .. " : " .. b.Publisher .. ", " .. mw.text.truncate(b.PublicationYear,4,'') .. ". " .. b.Url
end,
["interview"] = function (b)
return b.TitleItem .. ", {{int:Template-entretien_realise_par}}" .. b.Interviewer .. ". " .. b.Medium .. ", " .. b.Date .. ". " .. b.Archive .. ". " .. b.Url
end,
["videoRecording"] = function (b)
return b.TitleItem .. ". " .. b.Place .. " : " .. b.Publisher .. ", " .. b.Date .. ". " .. b.Url .. ", {{int:Template-Page_consulte_le}}" .. b.AccessDate
end,
["presentation"] = function (b)
return b.TitleItem .. ". " .. b.Place .. ", " .. b.Date
end,
["newspaperArticle"] = function (b)
return b.TitleItem .. ". " .. b.PublicationTitle .. ", " .. b.Date .. ". " .. b.Url .. ", {{int:Template-Page_consulte_le}}" .. b.AccessDate
end,
["webpage"] = function (b)
return b.TitleItem .. ". " .. b.PublicationTitle .. ", " .. b.Date .. ". " .. b.Url .. ", {{int:Template-Page_consulte_le}}" .. b.AccessDate
end,
["blogPost"] = function (b)
return b.TitleItem .. ". " .. b.PublicationTitle .. ", " .. b.Date .. ". " .. b.Url .. ", {{int:Template-Page_consulte_le}}" .. b.AccessDate
end,
}
function p.tableRef(rr,refer) -- Place la référence Zref dans la table result dont les clefs sont les champs (ex. Nom, Prénom, Date de naissance...)(Ref[3]) et les valeurs des tables de tables contenant clef Zotero et précision.
local ref = mw.text.split(rr,'+')
if ref[3] then
if not refer[ref[3]] then refer[ref[3]] = '' end
refer[ref[3]] = refer[ref[3]] .. modelRef(ref[1],ref[2],ref[3])
end
end
function p.split2(frame)
local res,precision = '',''
local ref = frame.args['ref']:gsub('(.-)%s*$','%1')
local precision = frame.args['precision']:gsub("[\n\r]","")
local compat = frame.args['compat']:gsub("[\n\r]","")
if #ref < 2 then
return ''
else
return modelRef(ref,precision,frame.args['field'],compat)
end
end
function modelRef(ref,precision,field,compat)
local content, pr = "", ""
r = mw.text.truncate(ref,-8,'')
if bbib[r] then
b = bbib[r]
if #b.Author > 1 then
content = b.Author .. ". "
else
content = b.Editor .. "ed"
end
if #precision > 1 then
precision = ". " .. precision
end
content = content .. model[b["ItemType"]](b)
else
content = ref
end
local name = mw.hash.hashValue( 'sha1', content .. pr )
if field ~= "Publication" and field ~= "Reference" then
if #compat < 1 then
return '<ref name="' .. name .. '">' .. content .. precision .. '</ref>'
else
return '{{#tag:ref|' .. content .. precision .. '|name=' .. name .. '}}'
end
else
return "*" .. content .. precision .. "\n"
end
end
function p.modelRefPub(rr)
local ct, pr, r = '','', mw.text.truncate(rr[1],-8,'')
if bbib[r] then
b = bbib[r]
if #b.Author > 1 then
ct = string.gsub(b.Author,";"," ; ") .. ". "
else
ct = b.Editor .. "ed"
end
if #rr[2] > 1 then
pr = ". " .. rr[2]
end
ct = ct .. model[b["ItemType"]](b)
else
ct = rr[1]
end
return "*" .. ct .. pr .. "\n"
end
function p.modelRefNote(rr)
local ct, pr, r = '','', mw.text.truncate(rr[1],-8,'')
if bbib[r] then
b = bbib[r]
if #b.Author > 1 then
ct = string.gsub(b.Author,";"," ; ") .. ". "
else
ct = b.Editor .. "ed"
end
if #rr[2] > 1 then
pr = ". " .. rr[2]
end
ct = ct .. model[b["ItemType"]](b)
else
ct = rr[1]
end
local name = mw.hash.hashValue( 'sha1', ct .. pr )
return '<ref name="' .. name .. '">' .. ct .. pr .. '.</ref>'
end
function p.split(frame)
local refer = ''
for _,rr in ipairs(mw.text.split(frame.args[1]:gsub("%s*#%s*","#"),'#')) do
refer = refer .. p.modelRefPub(mw.text.split(rr,'+'))
end
return refer
end
function p.splitTextN(refs)
local refer = ''
if refs and #refs > 4 then
for _,rr in ipairs(mw.text.split(refs:gsub("%s*#%s*","#"),'#')) do
if #rr > 4 then
refer = refer .. p.modelRefNote(mw.text.split(rr,'+'))
end
end
end
return refer
end
function p.splitTextRP(refs)
local refer = ''
if refs and #refs > 4 then
for _,rr in ipairs(mw.text.split(refs:gsub("%s*#%s*","#"),'#')) do
if #rr > 4 then
refer = refer .. p.modelRefPub(mw.text.split(rr,'+'))
end
end
end
return refer
end
return p