Módulo:ABNT: mudanças entre as edições

Ir para navegação Ir para pesquisar
imported>Jaideraf
Sem resumo de edição
imported>Jaideraf
(doc)
 
function p.CreateReference( frame )
-- Define o alvo da referência: pode ser o primeiro parâmetro passado à predefinição,
-- predefinição, o valor da query string "fullpagename" (via UrlGetParameters) ou o título da página.
-- (via UrlGetParameters) ou o título da página.
local target = frame:getParent().args[1]
if target == '' or target == nil then
target = mw.uri.decode( frame:callParserFunction( '#urlget', 'fullpagename' ) )
target = mw.title.getCurrentTitle().prefixedText
end
-- Alvo definido
-- Definir se há criador(es) para o início da referência
local creator = frame:callParserFunction{ name = '#show', args = { target, '?Has creator#', link = 'none', valuesep = '; '} }
-- Definir se há editores(es)colaboradores para o início da referência
local contributor = frame:callParserFunction{ name = '#show', args = { target, '?Has contributor#', link = 'none', valuesep = '; '} }
-- Definir o título e o subtítulo
local title = frame:callParserFunction{ name = '#show', args = { target, '?Display title of#', link = 'none' } }
title = string.gsub( title, '(:.*)', '<span style="font-weight: normal;">%1</span>')
-- Condição: entrada pelopelos autor, pelo contribuidoragentes OU pelo título
local agents={}
if #creator >= 1 or #contributor >= 1 then
table.insert(agents, creator) -- como criador vem do campo 1XX, não há mais de um valor
 
table.insert(agents, creator)
for v in string.gmatch(contributor, "([^;]+)") do -- como colaborador vem do campo 7XX, pode haver mais de um valor
table.insert(agents, v)
end
for k, v in pairs(agents) do
if string.match( v, '^(.*,.*),') then
agents[k] -- ='Assis, string.match(Machado vde, 1839-1908'^(.*,.*),') --> 'Assis, Machado de, 1839-1908'
agents[k] = string.match( v, '^(.*,.*),')
end
end
for k, v in pairs(agents) do
if string.match( v, '^(.*)%s%(') then
agents[k] = string.match( v, '^(.*)%s%(') -- 'Tolkien, J. R. R. (John Ronald Reuel), 1892-1973' > 'Tolkien, J. R. R.'
agents[k] = string.match( v, '^(.*)%s%(')
end
end
 
agentstragentStr = table.concat(agents, "; ")
agentstragentStr = frame:callParserFunction{ name = '#regex', args = { agentstragentStr, '/(^.*?,)|(;.*?,)/', '<span style="text-transform: uppercase;">$1$2</span>' } }
reference = agentstragentStr .. '. <b>' .. title .. '</b>. '
 
else
-- Entrada pelo título
reference = string.gsub( title, '^(.-%s)', '<span style="text-transform: uppercase;">%1</span>. ')
 
end
-- Entrada e título definidos