Module:Infobox road/length/sandbox: Difference between revisions
Appearance
Content deleted Content added
there |
try again |
||
Line 7: | Line 7: | ||
function p._length(desc, num, args) |
function p._length(desc, num, args) |
||
local |
local descr = desc or "length" |
||
local km = args[ |
local km = args[descr .."_km" .. num] or '' |
||
local mi = args[ |
local mi = args[descr .."_mi" .. num] or '' |
||
local ref = args[ |
local ref = args[descr .."_ref" .. num] or '' |
||
local notes = args[ |
local notes = args[descr .."_notes" .. num] or '' |
||
local first, second, unit, unit2 |
local first, second, unit, unit2 |
||
Line 65: | Line 65: | ||
local num = '' |
local num = '' |
||
return p._length( |
return p._length(constr, num, args) |
||
end |
end |
||
Revision as of 06:36, 18 September 2021
![]() | 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(desc, num, args)
local descr = desc or "length"
local km = args[descr .."_km" .. num] or ''
local mi = args[descr .."_mi" .. num] or ''
local ref = args[descr .."_ref" .. num] or ''
local notes = args[descr .."_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 .. " ("}} .. ")<div>" .. notes .. "</div>"
elseif notes == '' and first < '1' then
return frame:expandTemplate{ title = 'cvt', args = { first, unit, unit3, disp = "x", ref .. " ("}} .. ")<div>" .. notes .. "</div>"
elseif notes ~= '' then
return frame:expandTemplate{ title = 'cvt', args = { first, unit, unit2, disp = "x", ref .. " ("}} .. ")<div>" .. notes .. "</div>"
else
return frame:expandTemplate{ title = 'cvt', args = { first, unit, unit2, disp = "x", ref .. " ("}} .. ")"
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(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 = ''
return p._length(planned, 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 = ''
return p._length(constr, 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 = ''
return p._length(overall, num, args)
end
return p