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

De Wikincat
Ir para navegação Ir para pesquisar
imported>Jaideraf
(Criou página com '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 strin...')
 
imported>Jaideraf
Sem resumo de edição
Linha 18: Linha 18:
local editor = frame:callParserFunction{ name = '#show', args = { target, '?Has editor#', link = 'none', valuesep = '; '} }
local editor = frame:callParserFunction{ name = '#show', args = { target, '?Has editor#', 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, '?Has full title#', 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 OU pelo editor OU pelo título
-- Condição: entrada pelo autor OU pelo editor OU pelo título

Edição das 14h20min de 8 de junho de 2021

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) 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 = 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 = ';&#32;'} }
    -- Definir se há editores(es) para o início da referência
    local editor = frame:callParserFunction{ name = '#show', args = { target, '?Has editor#', 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 pelo autor OU pelo editor OU pelo título
    if #creator >= 1 then
        creator = string.gsub( creator, '(,%s%d%d%d%d%-?%d-)', '')
        creator = frame:callParserFunction{ name = '#regex', args = { creator, '/(^.*?,)|(;.*?,)/', '<span style="text-transform: uppercase;">$1$2</span>' } }
        reference = creator .. '. <b>' .. title .. '</b>. '
    
    elseif #editor >= 1 then
        editor = frame:callParserFunction{ name = '#regex', args = { editor, '/(^.*?,)|(;.*?,)/', '<span style="text-transform: uppercase;">$1$2</span>' } }
        reference = editor .. ' (Org.). <b>' .. title .. '</b>. '
    
    else
        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' } }

    if #isbn >= 1 then
        isbn = frame:callParserFunction{ name = '#invoke:Converter', args = { 'ISBN', isbn, 'Sim' } }
        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