Jump to content

Module:Infobox road/name

Unchecked
From Wikipedia

Documentation for this module may be created at Module:Infobox road/name/doc

local p = {}

local format = mw.ustring.format

local names = {}
do
    function names:name(args)
        local countryArg = args.country
        local success, country = pcall(self.country, self, countryArg)
        if not(success) then
            return ''
        else
            local success, name = pcall(country.name, country, args)
            if success then
                return name
            elseif name == 'Invalid type' then
                local page = mw.title.getCurrentTitle()
                local pagename = page.prefixedText
                local ns = page.namespace
                return (ns == 0) and format("[[Category:Infobox road transclusion errors|& %s]]", pagename) or error(name, 0)
            else
                error(name, 0)
            end
        end
    end
    function names:country(name)
        local country = self[name]
        if country then return country end
        local module = require(format("Module:Infobox road/name/%s", name))
        return module.names
    end
end

p.names = names

function p._name(args)
    return names:name(args)
end

function p.name(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 state = config.state or args.state
    state = (state ~= '') and state or nil
    local province = config.province or args.province
    province = (province ~= '') and province or nil
    local type = config.type or args.type
    local subtype = config.subtype or args.subtype or nil
    local route = args.num or args.route or config.route or config.num or "{{{route}}}"
    local country = config.country or args.country
    return p._name{country=country, state=state, province=province, type=type, route=route, subtype=subtype}
end

return p