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

De Wikincat
Ir para navegação Ir para pesquisar
imported>Jaideraf
(teste)
imported>Jaideraf
Sem resumo de edição
 
(12 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 2: Linha 2:


function p.CreateReference( frame )
function p.CreateReference( frame )
-- Define o alvo da referência: pode ser o primeiro parâmetro passado à predefinição,
-- Define o alvo da referência: pode ser o primeiro parâmetro passado à
-- o valor da query string "fullpagename" (via UrlGetParameters) ou o título da página.
-- predefinição; o valor da query string "fullpagename"
-- (via UrlGetParameters); o parâmetro nomeado Page (via WSSearchFront);
local target = frame:getParent().args[1]
-- ou o título da página.
local target = frame:getParent().args[1]
if target == '' or target == nil then
if target == '' or target == nil then
target = mw.uri.decode( frame:callParserFunction( '#urlget', 'fullpagename' ) )
target = mw.uri.decode( frame:callParserFunction( '#urlget', 'fullpagename' ) )
end
if target == '' or target == nil then
target = frame:getParent().args.Page
end
end
if target == '' or target == nil then
if target == '' or target == nil then
target = mw.title.getCurrentTitle().prefixedText
target = mw.title.getCurrentTitle().prefixedText
end
end
local reference
-- Alvo definido
-- Alvo definido
-- Definir se há criador(es) para o início da referência
-- Definir se há criador(es) para o início da referência
local creator = 'Hitzler, Pascal' -- frame:callParserFunction{ name = '#show', args = { target, '?Has creator#', link = 'none', valuesep = '; '} }
local creator = frame:callParserFunction{ name = '#show', args = { target, '?Has creator#', link = 'none', valuesep = '; '} }
-- Definir se há editores(es) para o início da referência
-- Definir se há colaboradores para o início da referência
local contributor = 'Krötzsch, Markus; Rudolph, Sebastian' -- frame:callParserFunction{ name = '#show', args = { target, '?Has contributor#', link = 'none', valuesep = '; '} }
local contributor = frame:callParserFunction{ name = '#show', args = { target, '?Has contributor#', link = 'none', valuesep = '; '} }
-- Definir o título e o subtítulo
-- Definir o título e o subtítulo
local title = frame:callParserFunction{ name = '#show', args = { target, '?Display title of#', link = 'none' } }
local title = frame:callParserFunction{ name = '#show', args = { target, '?Display title of#', link = 'none' } }
title = string.gsub( title, '(:.*)', '<span style="font-weight: normal;">%1</span>')
title = string.gsub( title, '(:.*)', '<span style="font-weight: normal;">%1</span>')
-- Condição: entrada pelo autor, pelo contribuidor OU pelo título
-- Condição: entrada pelos agentes OU pelo título
local agents={}
local agents={}
local newagents={}
local newnewagents={}
if #creator >= 1 or #contributor >= 1 then
if #creator >= 1 or #contributor >= 1 then
if creator ~= '' then
table.insert(agents, creator) -- como criador vem do campo 1XX, não há mais de um valor
end


for v in string.gmatch(contributor, "([^;]+)") do -- como colaborador vem do campo 7XX, pode haver mais de um valor
table.insert(agents, creator)
table.insert(agents, v)
end
for v in string.gmatch(contributor, "([^;]+)") do
table.insert(agents, v)
end
for v in pairs(agents) do
if string.match( v, '^(.*,.*),') then
v = string.match( v, '^(.*,.*),') -- Assis, Machado de, 1839-1908
table.insert(newagents, v)
end
end
for v in pairs(newagents) do
if string.match( v, '^(.*)%s%(') then
v = string.match( v, '^(.*)%s%(') -- Tolkien, J. R. R. (John Ronald Reuel), 1892-1973
table.insert(newnewagents, v)
end
end


for k, v in pairs(agents) do
agentstr = table.concat(newnewagents, "; ")
if string.match( v, '^(.*,.*),') then
agentstr = frame:callParserFunction{ name = '#regex', args = { agentstr, '/(^.*?,)|(;.*?,)/', '<span style="text-transform: uppercase;">$1$2</span>' } }
reference = agentstr .. '. <b>' .. title .. '</b>. '
-- 'Assis, Machado de, 1839-1908' > 'Assis, Machado de'
agents[k] = string.match( v, '^(.*,.*),')
else
end
end
reference = string.gsub( title, '^(.-%s)', '<span style="text-transform: uppercase;">%1</span>') .. '. '


for k, v in pairs(agents) do
if string.match( v, '^(.*)%s%(') then
-- 'Tolkien, J. R. R. (John Ronald Reuel), 1892-1973' > 'Tolkien, J. R. R.'
agents[k] = string.match( v, '^(.*)%s%(')
end
end

local agentStr = table.concat(agents, "; ")
agentStr = frame:callParserFunction{ name = '#rreplace', args = { agentStr, '/(^.*?,)|(;.*?,)/', '<span style="text-transform: uppercase;">$1$2</span>' } }
reference = agentStr .. '. <b>' .. title .. '</b>. '

else
-- Entrada pelo título
reference = string.gsub( title, '^(.-%s)', '<span style="text-transform: uppercase;">%1</span>. ')
end
end
-- Entrada e título definidos
-- Entrada e título definidos
Linha 100: Linha 104:
-- Verificar se há ISBN
-- Verificar se há ISBN
local isbn = frame:callParserFunction{ name = '#show', args = { target, '?Has ISBN#', link = 'none' } }
local isbn = frame:callParserFunction{ name = '#show', args = { target, '?Has ISBN#', link = 'none' } }
isbn = string.match( isbn, '^%d+')
isbn = string.match( isbn, '^%d+') or ''


if #isbn >= 1 then
if #isbn >= 1 then
isbn = frame:callParserFunction{ name = '#invoke:Converter', args = { 'ISBN', isbn, 'Sim' } }
isbn = frame:callParserFunction{ name = '#invoke:Hyphenate', args = { 'ISBN', isbn } }
reference = reference .. ' ISBN ' .. isbn .. '. '
reference = reference .. ' ISBN ' .. isbn .. '. '
end
end

Edição atual tal como às 11h04min de 3 de janeiro de 2023

A documentação para este módulo pode ser criada em Módulo:ABNT/doc

local p = {}

function p.CreateReference( frame )
    -- Define o alvo da referência: pode ser o primeiro parâmetro passado à
    -- predefinição; o valor da query string "fullpagename"
    -- (via UrlGetParameters); o parâmetro nomeado Page (via WSSearchFront); 
    -- 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' ) )
    end
    if target == '' or target == nil then
        target = frame:getParent().args.Page
    end
    if target == '' or target == nil then
        target = mw.title.getCurrentTitle().prefixedText
    end
    local reference
    -- 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 = ';&#32;'} }
    -- Definir se há colaboradores para o início da referência
    local contributor = frame:callParserFunction{ name = '#show', args = { target, '?Has contributor#', link = 'none', valuesep = ';&#32;'} }
    -- 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 pelos agentes OU pelo título
    local agents={}
    if #creator >= 1 or #contributor >= 1 then
      if creator ~= '' then
        table.insert(agents, creator) -- como criador vem do campo 1XX, não há mais de um valor
      end

      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
          -- 'Assis, Machado de, 1839-1908' > 'Assis, Machado de'
            agents[k] = string.match( v, '^(.*,.*),')
        end
      end

      for k, v in pairs(agents) do
        if string.match( v, '^(.*)%s%(') then
          -- 'Tolkien, J. R. R. (John Ronald Reuel), 1892-1973' > 'Tolkien, J. R. R.'
            agents[k] = string.match( v, '^(.*)%s%(')
        end
      end

      local agentStr = table.concat(agents, "; ")
      agentStr = frame:callParserFunction{ name = '#rreplace', args = { agentStr, '/(^.*?,)|(;.*?,)/', '<span style="text-transform: uppercase;">$1$2</span>' } }
      reference = agentStr .. '. <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
    -- Verificar se há edição
    local edition = frame:callParserFunction{ name = '#show', args = { target, '?Has designation of edition#', link = 'none' } }

    if #edition >= 1 then
        edition = string.gsub( edition, 'edição', 'ed.')
        reference = reference .. edition .. '. '
    end
    -- Verificar se há local de publicação
    local place = frame:callParserFunction{ name = '#show', args = { target, '?Has place of publication#', link = 'none', valuesep = ';&#32;' } }
    place = string.gsub( place, ';.*$', '')

    if #place >= 1 then
        reference = reference .. place .. ': '
    else
        reference = reference .. '[S.l.]: '
    end
    -- Verificar se há editora
    local publisher = frame:callParserFunction{ name = '#show', args = { target, '?Has publisher\'s name#', link = 'none', valuesep = ':&#32;' } }
    publisher = string.gsub( publisher, ':.*$', '')

    if #publisher >= 1 then
        reference = reference .. publisher .. ', '
    else
        reference = reference .. '[s.n.], '
    end
    -- Verificar se há ano de publicação
    local year = frame:callParserFunction{ name = '#show', args = { target, '?Has date of publication#-f[Y]', link = 'none' } }
    local cyear = frame:callParserFunction{ name = '#show', args = { target, '?Has copyright date#-f[Y]', link = 'none' } }

    if #year >= 1 then
        reference = reference .. year .. '. '
    elseif #cyear >= 1 then
        reference = reference .. cyear .. '. '
    else
        reference = reference .. '[19--? ou 20--?]. '
    end
    -- Verificar se há páginas
    local pages = frame:callParserFunction{ name = '#show', args = { target, '?Has extent#', link = 'none' } }
    pages = string.gsub( pages, 'páginas', 'p. ')

    if #pages >= 1 then
        reference = reference .. pages
    end
    -- Verificar se há ISBN
    local isbn = frame:callParserFunction{ name = '#show', args = { target, '?Has ISBN#', link = 'none' } }
    isbn = string.match( isbn, '^%d+') or ''

    if #isbn >= 1 then
        isbn = frame:callParserFunction{ name = '#invoke:Hyphenate', args = { 'ISBN', isbn } }
        reference = reference .. ' ISBN ' .. isbn .. '. '
    end
    -- Verificar se há URL
    local url = frame:callParserFunction{ name = '#show', args = { target, '?Has uniform resource locator#', link = 'none' } }

    if #url >= 1 then
        reference = reference .. ' Disponível em: ' .. url .. '. Acesso em: ' .. string.lower( frame:callParserFunction{ name = '#time',  args = { 'j M. Y' } } ) .. '.'
    end
    -- Retirar pontos repetidos
    reference = string.gsub( reference, '%.%.', '.')
    -- Exibe a referência
    return reference

end
return p