Jump to content

Module:Infobox road/length/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
fix
shorten
Line 47: Line 47:
local num = config.num or ''
local num = config.num or ''
local desc = "length"
local desc = config.desc or "length"
return p._length(desc, num, args)
end
function p.free(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 = ''
local desc = "free"
return p._length(desc, num, args)
end
function p.tolled(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 = ''
local desc = "tolled"
return p._length(desc, num, args)
end

function p.planned(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 = ''
local desc = "planned"
return p._length(desc, num, args)
end
function p.constr(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 = ''
local desc = "constr"
return p._length(desc, num, args)
end
function p.overall(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 = ''
local desc = "overall"
return p._length(desc, num, args)
return p._length(desc, num, args)
end
end

Revision as of 08:35, 18 September 2021

local p = {}

local concat = table.concat
local insert = table.insert
local format = mw.ustring.format
local frame = mw.getCurrentFrame()

function p._length(desc, num, args)
	local desc = desc
	local km = args[desc .."_km" .. num] or ''
    local mi = args[desc .."_mi" .. num] or ''
    local ref = args[desc .."_ref" .. num] or ''
    local notes = args[desc .."_notes" .. num] or ''

    local first, second, unit, unit2
    if mi ~= '0' and km == '' then
        first = mi
        second = km
        unit = "mi"
        unit2 = "km"
        unit3 = "m"
    else
        first = km
        second = mi
        unit = "km"
        unit2 = "mi"
        unit3 = "mi ft"
    end

    if mi == '' and km == '' then
        return nil
    elseif 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;("}} .. ")<div>" .. notes .. "</div>"
    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 ''
    local desc = config.desc or "length"
    return p._length(desc, num, args)
end

return p