Modulo:Infobox nave: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
refactoring speed, fix bug
Moroboshi (discussione | contributi)
fix gestione errori, ulteriori commenti
Riga 1:
local p = {}
local getArgs = require('Module:Arguments').getArgs
local error_flag = false
 
---============================================================
Line 69 ⟶ 70:
end
 
---============================================================
-- Return formatted error message and set error_flag to true
---============================================================
local function add_error(ignore_error, msg)
if ignore_error then return '' end
error_flag = true
local current_page = mw.title.getCurrentTitle()
if current_page.namespace == 0 then
msg = msg .. "[[Categoria:Errori di compilazione del template Infobox nave]]"
end
return '<sup class="error" style="font-size:small;">' .. msg .. '</sup>'
end
 
local function format_m(m1_raw, m2_raw, factor, m_type, m1_unit, m2_unit, ignore_error)
if not (m1_raw or m2_raw) then
return
Line 103 ⟶ 104:
return m1_formatted, m2_formatted
end
 
 
---============================================================
Riga 115:
local spd_type = args[3]
if spd_kmh == nil and spd_kn == nil then return '' end
kn_formatted, kmh_formatted = format_m(spd_kn, spd_kmh, 1.852, "velocità", "nodi", "km/h", true)
local out = {}
if spd_type then dump(out, spd_type, ":&nbsp;") end
Riga 127:
end
 
---============================================================
-- Format range data (knots to km/h and nmi to km, or viceversa)
---============================================================
function p.range(frame)
local args = getArgs(frame)
Line 135 ⟶ 138:
local range_kmh = args[5]
local out = {}
local nmi_formatted, km_formatted = format_m(range_nmi, range_km, 1.852, "distanza", "miglia marine", "km")
local kn_formatted, kmh_formatted = format_m(range_kn, range_kmh, 1.852, "velocità", "nodi", "km/h")
if range_type then dump(out, range_type, ":") end
if nmi_formatted then
Line 151 ⟶ 154:
end
if nmi_formatted then dump (out, ")") end
end
-- add category error if necessary
if error_flag then
local current_page = mw.title.getCurrentTitle()
if current_page.namespace == 0 then
msg = msg .. dump(out, "[[Categoria:Errori di compilazione del template Infobox nave]]")
end
end
return table.concat(out)