
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:Itemlist/man (modifica · cronologia)
Sandbox: Modulo:Itemlist/sandbox (modifica · cronologia) · Test: Modulo:Itemlist/test (modifica · cronologia · Esegui)
Per come utilizzare questo modulo si veda il manuale dei template Citylist e Destinationlist.
--[[ Source script: https://it.wikivoyage.org/wiki/Modulo:Itemlist Maintainer: Andyrom75 Lazy loads: require('Modulo:Avviso').avviso ]] local Marker = require('Modulo:Marker').MarkerModule local function _isDefined(s) return s ~= '' and s end local function _numberedList( t ) local _numbT = {} for key, val in pairs(t) do if tonumber(key) then _numbT[#_numbT+1] = val end end return _numbT end function _validateParams( params ) local validParams = { titolo = true, nome = true, alt = true, lat = true, long = true, descrizione = true, immagine = true, wikidata = true } local invalidParams = '' for key, _ in pairs( params ) do if not validParams[key] then invalidParams = invalidParams .. '<b>' .. key ..'</b>; ' end end return _isDefined(invalidParams) and ('[[Categoria:Itemlist con errori di compilazione]]<span class="debuginfo" style="display:none;">Sono presenti parametri non gestiti: '.. invalidParams .. '</span>') or '' end function _item(frame, tipo) local args = frame.args local output = '' if _isDefined(args.titolo) then output = '<b>' .. args.titolo .. '</b>\n' end local MarkerArgs = { counter = tipo or 'listing', tipo = tipo or 'listing', nome = args.nome, lat = args.lat, long = args.long, immagine = args.immagine, wikidata = args.wikidata } output = output .. '*' .. Marker{ args = MarkerArgs } if _isDefined(args.alt) then output = output .. " (" .. args.alt .. ")" end if _isDefined(args.descrizione) then output = output .. " — " .. args.descrizione end --Categorizzo le pagine aventi item senza parametro nome if not _isDefined( args.nome ) then output = output .. '<span class="debuginfo" style="display:none;">Parametro nome assente</span>[[Categoria:Itemlist con errori di compilazione]]' end --Categorizzo le pagine aventi item senza parametro wikidata if not _isDefined( args.wikidata ) then output = output .. (mw.title.getCurrentTitle().namespace == 0 and '<span class="debuginfo" style="display:none;">Parametro wikidata assente o non compilato</span>[[Categoria:Itemlist con errori di compilazione]]' or '') end return output .. _validateParams( args ) .. '\n' .. MarkerArgs.tipo end local function _itemlist(frame, listType) local args = frame.args local output = '' local count = 0 local markerType = (listType == 'citylist') and 'city' or 'vicinity' --mi assicuro di avere una lista con solo chiavi numeriche senza duplicati local numberedArgs = _numberedList(args) for _, val in ipairs(numberedArgs) do if (_ <= 20) and val then val, count = string.gsub( val, '\n' .. markerType .. '$', '') if count == 0 then val, count = string.gsub( val, '\n[^\n]*(.)$', '') val = val .. ((count == 0) and '' or '<span class="debuginfo" style="display:none;">Il tipo di elemento non è coerente col tipo di template</span>[[Categoria:Itemlist con errori di compilazione]]') end output = output .. '\n' .. val end end output = '<div id="' .. listType .. '">' .. output .. '</div>' if #numberedArgs > 20 then output = require('Modulo:Avviso').avviso{args={tipo = 'stile', testo = 'Il template è pensato per gestire fino a 20 località, le successive non saranno mostrate. Seleziona le più significative eliminando le altre.'}} .. output if mw.title.getCurrentTitle().namespace == 0 then output = output .. '[[Categoria:Articoli con problemi di stile]][[Categoria:Itemlist con errori di compilazione]]' end end return output end local p = {} function p.cityitemTemplate(frame) return _item(frame:getParent(), 'city') end function p.cityitem(frame) return _item(frame, 'city') end function p.destinationitemTemplate(frame) return _item(frame:getParent(), 'vicinity') end function p.destinationitem(frame) return _item(frame, 'vicinity') end function p.citylistTemplate(frame) return _itemlist(frame:getParent(), 'citylist') end function p.citylist(frame) return _itemlist(frame, 'citylist') end function p.destinationlistTemplate(frame) return _itemlist(frame:getParent(), 'destinationlist') end function p.destinationlist(frame) return _itemlist(frame, 'destinationlist') end return p