Modulo:Periodo attività musicale/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
periodi formati da un solo anno specificati ripetendo l'anno in inizio e fine |
m Bot: rimuovo no globals obsoleto |
||
(7 versioni intermedie di un altro utente non mostrate) | |||
Riga 5:
]]--
require('
local getArgs = require('Modulo:Arguments').getArgs
local cfg = mw.loadData('Modulo:Periodo attività musicale/Configurazione')
local errorCategory = '
local trackingCategory = '
local maxIntervals = 10
local p = {}▼
-- Verifica se il decennio è nel formato accettato "anni nnnn" e con un valore consentito.
local function errhandler(msg)▼
--
-- @param {string} value
return string.format('<span class="error">%s</span>[[%s]]', msg, cat)▼
-- @return {string} la stringa non modificata o nil se non è un decennio valido
return value and (value:match('^anni 19[0-9]0$') or value:match('^anni 20[0-2]0$'))
end
-- Parsifica i parametri relativi al periodo di attività musicale:
-- "anno inizio attività N", "anno fine attività N" e "note periodo attività N".
--
-- Restituisce una sequence Lua con elementi con chiavi▼
-- @param {table} args
-- "start", "ending" ("end" è una parola riservata) e "note".▼
local function parseArgs(args)
local ret = {}
Line 34 ⟶ 38:
}
if interval.start or interval.ending then
if interval.start then▼
if not tonumber(interval.start) then▼
error('anno inizio attività' .. n .. ' non valido', 3)▼
if interval.ending then▼
if not tonumber(interval.ending) and interval.ending ~= 'in attività' then▼
table.insert(ret, interval)
else
Line 53 ⟶ 47:
end
-- Formatta il valore del parametro
--
-- @param {string} value
-- @param {table} confCat
-- @return {string} il valore formattato
-- @return {string} l'eventuale categoria per l'anno di costituzione dell'artista
local function formatStartYear(value, confCat)
local ret, cat
if isDecade(value) then
elseif tonumber(value) then
cat = confCat.inizio and (confCat.inizio .. ' ' .. value) or nil
ret = cat and string.format('[[:Categoria:%s|%s]]', cat, value) or string.format('[[%s]]', value)
else
cat = confCat.inizio_assente
ret = value or '?'
end
return ret, cat
end
-- Formatta il valore del parametro
--
-- @param {string} value
-- @param {table} confCat
-- @return {string} il valore formattato
-- @return {string} l'eventuale categoria per l'anno di scioglimento dell'artista
local function formatEndYear(value, confCat)
local ret, cat
if isDecade(value) then
ret = string.format('[[%s]]', value)
▲ ret = cat and string.format('[[:%s|%s]]', cat, value) or value
cat = confCat.fine and (confCat.fine .. ' ' .. value) or nil else
cat = confCat.fine_assente
ret = value or '?'
end
return ret, cat
end
-- =============================================================================
-- Funzioni esportate
-- =============================================================================
function p._main(args)▼
▲local p = {}
-- Funzione per {{#invoke:Periodo attività musicale|main}}▼
local args = getArgs(frame, { parentOnly = false })▼
local formattedIntervals, categories = {}, {}
local ns0 = mw.title.getCurrentTitle().namespace == 0
local sepCat = args.debug and '<br />' or ''
local singleYear = false
-- categorie configurate per il
local tipo_artista = args['tipo artista'] and mw.ustring.lower(args['tipo artista']) or
local confCat = cfg.categorie[cfg.alias[tipo_artista] or tipo_artista] or
-- parsifica gli intervalli richiesti
Line 105 ⟶ 117:
start, cat = formatStartYear(interval.start, confCat)
table.insert(categories, cat)
▲
table.insert(categories, errorCategory)
else
start = '?'
▲ start = interval.start and string.format('[[%s]]', interval.start) or '?'
end
Line 112 ⟶ 129:
ending, cat = formatEndYear(interval.ending, confCat)
table.insert(categories, cat)
ending = string.format('[[%s]]', interval.ending)
▲
table.insert(categories, errorCategory)
else
ending = '?'
▲ ending = interval.ending and string.format('[[%s]]', interval.ending) or '?'
end
Line 142 ⟶ 164:
for i = 1, #categories do
categories[i] = string.format('[[%
end
return table.concat(formattedIntervals, '<br />') .. sepCat ..
((ns0 or args.debug) and table.concat(categories, sepCat) or '')
▲-- Funzione per {{#invoke:Periodo attività musicale|main}}
▲ local args = getArgs(frame, { parentOnly = false })
end
|