Modulo:Tracce/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
ammetto numerazione discontinua delle tracce
m indentazione con tab
Riga 7:
-- Protects a string that will be wrapped in wiki italic markup '' ... ''
local function safeforitalics( str )
if str ~= nil and str ~= '' then
if str:sub(1,1) == "'" then str = "<span></span>" .. str end
if str:sub(-1,-1) == "'" then str = str .. "<span></span>" end
end
return str
end
 
Riga 99:
]]--
local function componi_tracce(args)
-- array per accumulare le righe della lista man mano che vengono elaborate
local tracks = {}
-- compone la testata dell'elenco tracce
local testata = ""
local no_autore = false
local autoreTestoeMusica = args["Autore testi e musiche"] or ""
if autoreTestoeMusica ~= "" then
testata = "Testi e musiche di " .. autoreTestoeMusica
else
local autoreTesti = args["Autore testi"] or ""
local autoreMusiche = args["Autore musiche"] or ""
if autoreTesti ~= "" then
testata = "Testi di " .. autoreTesti
if autoreMusiche ~= "" then testata = testata .. ", musiche di " .. autoreMusiche end
elseif autoreMusiche ~= "" then
testata = "Musiche di " .. autoreMusiche
else
no_autore = true
end
end
local edizioni = args["Edizioni"] or ""
if edizioni ~= "" then
if no_autore then
testata = "Edizioni musicali " .. edizioni .."."
else
testata = testata .. "; edizioni musicali " .. edizioni .. "."
end
elseif not no_autore then
testata = testata .. "."
end
local corsivo = true
if args["Corsivo"] == "no" then
corsivo = false
end
table.insert(tracks, testata)
-- compone la lista dei parametri
table.insert(tracks, "<ol>")
local visualizza_durata = args["Visualizza durata totale"] or ""
local durata = 0
local somma_durata = false
if visualizza_durata == "si" or visualizza_durata == "sì" then somma_durata = true end
local nums = {}
for k, v in pairs(args) do
local numero_titolo = k:match('%D(%d+)$')
if tonumber(numero_titolo) then
local titolo = args['Titolo' .. numero_titolo] or ''
if v ~= '' and titolo == '' then
categories[#categories+1] = missing_title
elseif k == 'Titolo' .. numero_titolo and titolo ~= '' then
table.insert(nums, tonumber(numero_titolo))
end
end
end
table.sort(nums)
-- estrae le tracce dai parametri e inserisce i valori nella tabella tracks
for k, num in ipairs(nums) do
local new_track, durata_track = track(args, num, corsivo)
table.insert(tracks, new_track)
if somma_durata then durata = durata + durata_track end
if k ~= num then categories[#categories+1] = discontinuous_num end
end
table.insert(tracks, "</ol>")
if somma_durata then
table.insert(tracks, "Durata totale: " .. string.format("%d:%02.f", math.floor(durata/60) , durata % 60) .. "</p>")
end
return table.concat(tracks, "\n") .. table.concat(categories)
end
 
Riga 175:
]]--
function p.tracce(frame)
-- ottiene i parametri del template originale
local pframe = frame:getParent()
-- estrae tutti i parametri e li memorizza in una tabella
local args = {}
local titles = false
for k, v in pairs( pframe.args ) do
if v ~= nil then args[k] = v end
if k:match("^Titolo(%d+)$") then titles = true end
end
-- procede solo se c'è almeno un campo titolo
return titles and componi_tracce(args) or ""
end
 
-- Tavola di conversione per i parametri di en:template:Track_listing non indicizzati
local conversion_table = {
['all_writing'] = 'Autore testi e musiche',
['all_lyrics'] = 'Autore testi',
['all_music'] = 'Autore musiche',
['total_length'] = 'Visualizza durata totale'
}
 
-- Tavola di conversione per i parametri di en:template:Track_listing indicizzati
local conversion_table_index ={
['title'] = 'Titolo',
['note'] = 'Note',
['music'] = 'Autore musica',
['writer'] = 'Autore testo e musica',
['lyrics'] = 'Autore testo',
['length'] = 'Durata',
['extra'] = 'Extra'
}
 
Riga 214:
]]--
function p.en_tracks(frame)
local pframe = frame:getParent()
-- estrae tutti i parametri e li memorizza in una tabella (pframe ritorna una pseudotabella, vedi documentazione)
local args = {}
local primo_titolo
local log ={}
for k,v in pairs( pframe.args) do
if conversion_table[k] then -- Controlla s è un parametro non indicizzato
args[ conversion_table[k]] = v
else
-- estrae nome base e indice, se k=Title1 allora base_key=Title e pos=1
local base_key, pos = string.match(k, "(%D+)(%d+)$")
if pos and base_key and conversion_table_index[base_key] then --controlla se è un parametro indicizzato
args[conversion_table_index[base_key] .. pos] = v
pos = tonumber(pos)
if base_key == 'title' and (not primo_titolo or pos < primo_titolo) then
primo_titolo = pos
end
end
else -- non è neanche un parametro indicizzato, lo copia così com'è
args[k] = v
end
end
end
if args['Visualizza durata totale'] then args['Visualizza durata totale'] = 'si' end
if primo_titolo then
return componi_tracce(args, primo_titolo) -- table.concat(log, '\n*') --
else
return
end
end