Module:Infobox road/length

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 nmi = args["length_nmi" .. num] or ''
    local ref = args["length_ref" .. num] or ''
    local notes = args["length_notes" .. num] or ''

	if '' == mi and '' == km and '' == nmi then
	    return nil																-- none of these set, abandon
	end

    local first, unit, unit2, unit3
--    if nmi ~= '0' and mi == '' and km == '' then
	if tonumber (nmi) then
		first = nmi
		unit = "nmi"
		unit2 = "km mi"
		unit3 = "km mi"
--    elseif mi ~= '0' and km == '' then
	elseif tonumber (mi) then
		first = mi
		unit = "mi"
		unit2 = "km"
		unit3 = "m"
--    elseif km ~= '0' and mi == '' then
	elseif tonumber (km) then
		first = km
		unit = "km"
		unit2 = "mi"
		unit3 = "mi ft"
	else
		return nil																-- something other than numbers so abandon
    end

	if not first then
		return nil
	end
--    if mi == '' and km == '' and nmi == '' then
--        return nil
--    elseif notes ~= '' and first < '1' then
	if notes ~= '' and first < '1' then
    	return frame:expandTemplate{ title = 'cvt', args = { first, unit, unit3, disp = "x", ref .. "&nbsp;("}} .. ")<div>" .. notes .. "</div>"
    elseif notes == '' and first < '1' then
    	return frame:expandTemplate{ title = 'cvt', args = { first, unit, unit3, disp = "x", ref .. "&nbsp;("}} .. ")"
    elseif notes ~= '' then
		return frame:expandTemplate{ title = 'cvt', args = { first, unit, unit2, disp = "x", ref .. "&nbsp;("}} .. ")<div>" .. notes .. "</div>"
	else
    	return frame:expandTemplate{ title = 'cvt', args = { first, unit, unit2, disp = "x", ref .. "&nbsp;("}} .. ")"
    end
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

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.