Módulo:Citar mapa/Testes

Origem: Wikipédia, a enciclopédia livre.
local m = require('Módulo:Citação/CS1/Testes')

--[[--------------------------< m . m a p a >------------------------------------

Este é o método principal da predefinição {{citar mapa}}.

]]

m.mapa = function(frame)
    -- lista de parâmetros usado apenas neste módulo
    frame.whitelist = {
        folha = true,
        folhas = true,
        sheet = true,
        sheets = true,
        mapa = true,
        map = true,
        ['formato-mapa'] = true,
        ['map-format'] = true,
        mapurl = true,
        ['map-url'] = true,
        urlmapa = true,
        ['trans-map'] = true,
        ['mapa-trad'] = true,
        cartografia = true,
        cartography = true
    }
    local config, args, A = tratarArgumentos(frame)
    config.CitationClass = ''
    config.usaVolume = true
    config.usaIssue = true
    local classe = 'map'
    local sepc = set_style (A.Mode:lower())
    local use_lowercase = sepc == ','

    cfg.aliases.Chapter = {'mapa', 'map'}
    cfg.aliases.ChapterURL = {'urlmapa', 'mapurl', 'map-url'}
    cfg.aliases.ChapterFormat = {'formato-mapa', 'map-format'}
    cfg.aliases.TransChapter = {'trans-map', 'mapa-trad'}
    cfg.aliases.Cartography = {'cartografia', 'cartography'}
    cfg.aliases.Sheet = {'folha', 'sheet'}
    cfg.aliases.Sheets = {'folhas', 'sheets'}

    -- verifica por parâmetro |at= adicional. (sheet e sheets)
    select_one( args, {'at', 'sheet', 'sheets'}, 'redundant_parameters' )

    -- mapa no formato de livro não suporta o parâmetro issue
    if not is_set (A.Periodical) then
        A.Issue = ''
    end


    -- para forçar o upvalue da tabela 'origin' do metadados de 'A' a carregar o alias
    A:ORIGIN('Chapter')

    -- A.ChapterURL = A['MapURL']
    local ChapterURLorigin = A:ORIGIN('ChapterURL')
    local Periodical_origin = A:ORIGIN('Periodical')

    if is_set(A.Cartography ) then
        A.Cartography = sepc .. " " .. wrap_msg ('cartography', A.Cartography, use_lowercase)
    end
    if is_set( A.Scale ) then
        A.Scale = sepc .. " " .. A.Scale
    end

    A.TitleType = set_titletype (classe, A.TitleType)

     -- caso especial quando o mapa está num periódico
    if is_set (A.Periodical) then
        config.TituloFormatado = {}
        do
            local TransTitle = A.TransTitle
            if (is_set(Title)) then
                Title = kern_quotes (Title)
                Title = wrap_style ('quoted-title', Title)
                config.TituloFormatado.Title = Title
            end
            local TransTitle = A.TransTitle
            if (is_set(TransTitle)) then
                TransTitle= wrap_style ('trans-quoted-title', TransTitle )
                config.TituloFormatado = {TransTitle = TransTitle}
            end
        end
    end

    local coins_pages = get_coins_pages(first_set({A.Sheet, A.Sheets, A.Page, A.Pages, A.At}, 5))
    local page, pages = '', ''
    if 'jornal' == Periodical_origin or 'journal' == Periodical_origin then
        if is_set(A.Sheet) then
            A.Sheet = wrap_msg ('j-sheet', A.Sheet, use_lowercase)
        elseif is_set(A.Sheets) then
            A.Sheets = wrap_msg ('j-sheets', A.Sheets, use_lowercase)
        end
        -- mla sempre usa os prefixos p ou pp
        if A.Mode:lower() ~= 'mla' then
            if is_set(A.Page) then
                page = substitute(cfg.messages['j-page(s)'], A.Page)
            elseif is_set(A.Pages) then
                page = substitute (cfg.messages['j-page(s)'], A.Pages)
            end
            if is_set(A.TotalPages) then
                pages = substitute (cfg.messages['total-p'], {sepc, A.TotalPages})
        	end
        else
            page, pages = format_pages (A.Page, A.Pages, sepc, A.NoPP, use_lowercase, A.TotalPages)
        end
    else
        if is_set(A.Sheet) then
            A.Sheet = wrap_msg ('sheet', {sepc, A.Sheet}, use_lowercase)
        elseif is_set(A.Sheets) then
            A.Sheets = wrap_msg ('sheets', {sepc, A.Sheets}, use_lowercase)
        end
        page, pages = format_pages (A.Page, A.Pages, sepc, A.NoPP, use_lowercase, A.TotalPages)
    end


    local volume = A.Volume
    if in_array(Periodical_origin, {'revista', 'magazine'}) then
        if is_set (volume) and is_set (A.Issue) then
            volume = wrap_msg ('vol-no', {sepc, volume, A.Issue}, use_lowercase)
        elseif is_set (volume) then
            volume = wrap_msg ('vol', {sepc, volume}, use_lowercase)
        elseif is_set (A.Issue) then
            volume = wrap_msg ('issue', {sepc, A.Issue}, use_lowercase)
        else
            volume = ''
        end
    else
        volume = format_volume_issue (A.Volume, A.Issue, sepc)
    end

    -- Função com o código abstraído
    local B
    A, B = citation0( config, args, A)
    B.coins_table.Pages = coins_pages

    do
        local Section = A.Section
        local Sections = A.Sections
        local Inset = A.Inset

        if is_set( Inset ) then
            Inset = sepc .. " " .. wrap_msg ('inset', Inset, use_lowercase)
        end

        if is_set( Sections ) then
            Section = sepc .. " " .. wrap_msg ('sections', Sections, use_lowercase)
        elseif is_set( Section ) then
            Section = sepc .. " " .. wrap_msg ('section', Section, use_lowercase)
        end
        A.At = A.At .. Inset .. Section
    end

    B.Position = B.Position .. A.Sheet .. A.Sheets
    A.Page = page
    A.Pages = pages
    A.Volume = volume;

    -- formatação de Chapter diferenciada
    local no_quotes = false -- por padrão, inserirá aspas angulares
    if is_set (A.Contribution) and 0 < #B.c then -- se tiver colaborador(es)
        -- e um título de contribuição genérico
        if in_array (A.Contribution:lower(), cfg.keywords.contribution) then
            no_quotes = true -- então não se usará aspas angulares
        end
    end

    A.Chapter = format_chapter_title (A.ScriptChapter, A.Chapter, A.TransChapter, A.ChapterURL, ChapterURLorigin, no_quotes) -- A.Contribution também está em A.Chapter
    if is_set (A.Chapter) then
        A.Chapter = A.Chapter .. A.ChapterFormat ;
        if is_set (A.TitleType) then
            -- anotação de mapa aqui ao invés de estar após o título
            A.Chapter = A.Chapter .. ' ' .. A.TitleType
        end
        A.Chapter = A.Chapter.. B.sepc .. ' '
    -- se |chapter= não estiver definido, mas estiver |chapter-format= então ...
    elseif is_set (A.ChapterFormat) then
        A.Chapter = A.ChapterFormat .. B.sepc .. ' '
    end

    do
        local titulo = A.Mode == 'mla' and '' or A.Title
        if is_set (A.Chapter) then -- mapa num livro; TitleType é parte de Chapter
            B.tcommon = safe_join( {titulo, A.Format, A.Edition, A.Scale, A.Series, A.Language, A.Cartography, A.Others, B.Publisher, A.Volume}, B.sepc )
        elseif is_set (A.Periodical) then -- mapa num periódico
            B.tcommon = safe_join( {titulo, A.TitleType, A.Format, A.Periodical, A.Scale, A.Series, A.Language, A.Cartography, A.Others, B.Publisher, A.Volume}, B.sepc )
        else -- uma folha ou mapa independente
            B.tcommon = safe_join( {titulo, A.TitleType, A.Format, A.Edition, A.Scale, A.Series, A.Language, A.Cartography, A.Others, B.Publisher}, B.sepc )
        end
    end

    config.CitationClass = classe
    B.config = config

    return textoFinal(A, B)
end

return m