Module:Infobox road/meta/mask/subtype1

MyWikiBiz, Author Your Legacy — Friday November 22, 2024
< Module:Infobox road
Revision as of 23:22, 15 July 2021 by Zoran (talk | contribs) (Pywikibot 6.4.0)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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