Modulo:New Grove/sandbox

Versione del 14 ago 2015 alle 16:17 di Tino (discussione | contributi) (Tino ha spostato la pagina Modulo:Sandbox/Tino/New Grove a Modulo:New Grove/sandbox senza lasciare redirect)
local p = {}

-- shallow copy di un oggetto table
local function table_shallow_copy(obj)
    local copy = {}
    if type(obj) == 'table' then
        for key, val in pairs(obj) do
            copy[key] = val
        end
    end
    return copy
end

-- parametri posizionali: {{New Grove|edizione|nome|cognome|voce|volume|pagine|cid|wl}}
-- edizioni: 1, 2, inst, opera, american, art1, art2, jazz1, jazz2

function p.citation(frame)
    
    local pframe = frame:getParent()
    
    -- wl determina se inserire o meno un wikilink nel titolo dell'opera
    local wl = pframe.args[8] or pframe.args['wl'] or Nil
    wl = wl and wl ~= ''
    
    -- sceglie edizione (per avere i campi precompilati)
    local edition = pframe.args[1] or pframe.args['edizione'] or Nil
    
    -- shallow copy dei parametri
    local inner_args = table_shallow_copy(pframe.args)
    
    -- conversione parametri posizionali:
    -- il Modulo:Citazione e il Template:New Grove hanno un ordine diverso
    -- per i parametri posizionali
    inner_args['nome']    = pframe.args[2] or pframe.args['nome']
    inner_args['cognome'] = pframe.args[3] or pframe.args['cognome']
    inner_args['voce']    = pframe.args[4] or pframe.args['voce']
    inner_args['volume']  = pframe.args[5] or pframe.args['volume']
    inner_args['pagine']  = pframe.args[6] or pframe.args['pagine']
    inner_args['cid']     = pframe.args[7] or pframe.args['cid']
        
    -- New Grove ed. 1
    if edition == "1" then
        if wl then
            inner_args['titolo'] = "The New Grove Dictionary of Music and Musicians"
        else
            inner_args['titolo'] = "[[Grove Dictionary of Music and Musicians|The New Grove Dictionary of Music and Musicians]]"
        end
        inner_args['curatore'] = "Stanley Sadie"
        inner_args['edizione'] = "1ª ed."
        inner_args['editore']  = "MacMillian"
        inner_args['città']    = "Londra"
        inner_args['anno']     = "1980"
        inner_args['ISBN']     = "978-0333231111"
        
    -- New Grove ed. 2
    elseif edition == "2" then
        if wl then
            inner_args['titolo'] = "The New Grove Dictionary of Music and Musicians"
        else
            inner_args['titolo'] = "[[Grove Dictionary of Music and Musicians|The New Grove Dictionary of Music and Musicians]]"
        end
        inner_args['curatore']  = "Stanley Sadie"
        inner_args['curatore2'] = "John Tyrrell"
        inner_args['edizione']  = "2ª ed."
        inner_args['editore']   = "Oxford University Press"
        inner_args['anno']      = "2001"
        inner_args['ISBN']      = "978-0195170672"
        
    -- Grove Dictionary of Musical Instruments
    elseif edition == "inst" then
        inner_args['titolo']   = "The New Grove Dictionary of Musical Instruments"
        inner_args['curatore'] = "Stanley Sadie"
        inner_args['editore']  = "MacMillian"
        inner_args['città']    = "Londra"
        inner_args['anno']     = "1984"
        inner_args['ISBN']     = "0943818052"
        
    -- Grove Dictionary of Opera
    elseif edition == "opera" then
        if wl then
            inner_args['titolo'] = "[[New Grove Dictionary of Opera|The New Grove Dictionary of Opera]]"
        else
            inner_args['titolo'] = "The New Grove Dictionary of Opera"
        end
        inner_args['curatore'] = "Stanley Sadie"
        inner_args['edizione'] = "1ª ed."
        inner_args['editore']  = "MacMillian"
        inner_args['città']    = "Londra"
        inner_args['anno']     = "1992"
        inner_args['ISBN']     = "0333485521"
        
    -- Grove Dictionary of American Music
    elseif edition == "american" then
        inner_args['titolo']   = "The New Grove Dictionary of American Music"
        inner_args['curatore'] = "Stanley Sadie"
        inner_args['curatore'] = "Hugh Wiley Hitchcock"
        inner_args['editore']  = "MacMillian"
        inner_args['città']    = "Londra"
        inner_args['anno']     = "1986"
        inner_args['ISBN']     = "0333378792"
        
    -- Grove Dictionary of Art ed. 1
    elseif edition == "art1" then
        inner_args['titolo']    = "The Grove Dictionary of Art"
        inner_args['curatore']  = "Jane Turner"
        inner_args['edizione']  = "1ª ed."
        inner_args['editore']   = "Oxford University Press"
        inner_args['anno']      = "1996"
        inner_args['ISBN']      = "1884446000"
        
    -- Grove Dictionary of Art ed. 2
    elseif edition == "art2" then
        inner_args['titolo']    = "The Grove Dictionary of Art"
        inner_args['curatore']  = "Jane Turner"
        inner_args['edizione']  = "2ª ed."
        inner_args['editore']   = "Oxford University Press"
        inner_args['anno']      = "2003"
        inner_args['ISBN']      = "0195170687"
    
    -- Grove Dictionary of Jazz ed. 1
    elseif edition == "jazz1" then
        inner_args['titolo']    = "The New Grove Dictionary of Jazz"
        inner_args['curatore']  = "Barry Kernfeld"
        inner_args['edizione']  = "1ª ed."
        inner_args['editore']   = "MacMillian"
        inner_args['anno']      = "1988"
        inner_args['ISBN']      = "0312113579"
    
    -- Grove Dictionary of Jazz ed. 2
    elseif edition == "jazz2" then
        inner_args['titolo']    = "The New Grove Dictionary of Jazz"
        inner_args['curatore']  = "Barry Kernfeld"
        inner_args['edizione']  = "2ª ed."
        inner_args['editore']   = "Oxford University Press"
        inner_args['anno']      = "2003"
        inner_args['ISBN']      = "1561592846"
    end
    
    -- oggetto ambiente per la chiamata del Modulo:Citazione
    local cite_object = {
        cite_module = require("Modulo:Citazione"),
        args = inner_args,
        frame = {
            args = {}
        }
    }
    function cite_object.getParent()
        return cite_object.frame
    end
    
    -- chiama la funzione citation dal Modulo:Citazione
    return cite_object.cite_module.citation(cite_object)
end

return p