Module:Infobox road/length/sandbox
Appearance
![]() | This is the module sandbox page for Module:Infobox road/length (diff). |
local p = {}
local concat = table.concat
local insert = table.insert
local format = mw.ustring.format
local frame = mw.getCurrentFrame()
function p._length(num, args)
local km = args["length_km" .. num] or ''
local mi = args["length_mi" .. num] or ''
local ref = args["length_ref" .. num] or ''
local notes = args["length_notes" .. num] or ''
local first, second, unit
if mi ~= '0' and km == '' then
first = mi
second = km
unit = "mi"
else
first = km
second = mi
unit = "km"
end
local conversion
if mi == '0' and km == '0' then
return
else
return frame:expandTemplate{ title = 'cvt', args = { first, unit, disp = 'out'}}
end
local text = { first .. ' ' .. unit .. ref .. ' (' .. conversion .. ')' }
if notes ~= '' then
insert(text, "<div style='font-size:88%;'>" .. notes .. "</div>")
end
return concat(text)
end
function p.length(frame)
local pframe = frame:getParent()
local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
local num = config.num or ''
return p._length(num, args)
end
return p