Module:Infobox road/meta/mask/subtype1

MyWikiBiz, Author Your Legacy — Wednesday October 09, 2024
Jump to navigationJump to search

Documentation for this module may be created at Module:Infobox road/meta/mask/subtype1/doc

local p = {}

local subtypes = {["alt"] = "Alt", ["alternate"] = "Alt",
                  ["bus"] = "Bus", ["business"] = "Bus",
                  ["byp"] = "Byp", ["bypass"] = "Byp", ["by-pass"] = "Byp",
                  ["conn"] = "Conn", ["connector"] = "Conn",
                  ["emerg"] = "Emerg", ["emergency"] = "Emerg",
                  ["loop"] = "Loop",
                  ["old"] = "Old",
                  ["opt"] = "Opt", ["optional"] = "Opt",
                  ["scenic"] = "Scenic",
                  ["spur"] = "Spur",
                  ["temp"] = "Temp", ["temporary"] = "Temp",
                  ["toll"] = "Toll",
                  ["truck"] = "Truck", ["trk"] = "Truck"}

function p._subtype(subtype, hyphenate)
    local subtypeLowercase = string.lower(subtype)
    local hyphen = hyphenate and '-' or ''
    return hyphen .. (subtypes[subtypeLowercase] or '')
end

function p.subtype(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 subtype = args[1]
    if not(subtype) then return '' end
    local hyphenate = args[2] == 'yes'

    return p._subtype(subtype, hyphenate)
end

return p