Difference between revisions of "Module:Infobox road/abbrev"

From blackwiki
Jump to navigation Jump to search
test>Fredddie
(add)
test>Happy5214
(Use Module:Road data/parser and associated data)
Line 1: Line 1:
 +
-- Temporary migration module for abbreviations
 
local p = {}
 
local p = {}
  
local format = mw.ustring.format
+
local getArgs = require('Module:Arguments').getArgs -- Import module function to work with passed arguments
 
+
local parserModule = require "Module:Road data/parser" -- DEPLOY: Switch to main module
local typesModule = require "Module:Infobox road/abbrev/defs"
+
local parser = parserModule.parser
Country = typesModule.Country
 
Type = typesModule.Type
 
Abbr = typesModule.Abbr
 
 
 
local abbrevs = {}
 
do
 
    function abbrevs:abbr(args)
 
        local countryArg = args.country
 
        local success, country = pcall(self.country, self, countryArg)
 
        if not(success) then
 
            return ''
 
        else
 
            local success, abbr = pcall(country.abbr, country, args)
 
            if success then
 
                return abbr
 
            elseif abbr == '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(abbr, 0)
 
            else
 
                error(abbr, 0)
 
            end
 
        end
 
    end
 
    function abbrevs:country(name)
 
        local abbr = self[name]
 
        if abbr then return abbr end
 
        local module = require(format("Module:Infobox road/abbrev/%s", name))
 
        return module.abbrs
 
    end
 
   
 
    abbrevs.AUT = Country:newWithSimpleAbbrs{["A"] = "A%s", ["S"] = "S%s"} -- Austria
 
    abbrevs.BGD = Country:newWithSimpleAbbrs{["N"] = "N%s", ["R"] = "R%s", ["Z"] = "Z%s"} -- Bangladesh
 
    abbrevs.CHE = Country:newWithSimpleAbbrs{["A"] = "A%s"} -- Switzerland
 
    abbrevs.CHN = Country:newWithSimpleAbbrs{[{"G", "Ex", "Expwy"}] = "G%s", ["S"] = "S%s", ["X"] = "X%s"} -- China
 
    abbrevs.CYP = Country:newWithSimpleAbbrs{["A"] = "A%s", ["B"] = "B%s"} -- Cyprus
 
    abbrevs.CZE = Country:newWithSimpleAbbrs{["D"] = "D%s", ["R"] = "R%s"} -- Czech Republic
 
    abbrevs.DEU = Country:newWithSimpleAbbrs{["A"] = "A %s", ["B"] = "B %s"} -- Germany
 
    abbrevs.ECU = Country:newWithSimpleAbbrs{["E"] = "E%s"} -- Ecuador
 
    abbrevs.ESP = Country:newWithSimpleAbbrs{["A"] = "A-%s", ["AS"] = "AS-%s", ["E"] = "E-%s", ["M"] = "M-%s", ["R"] = "R-%s"} -- Spain
 
    abbrevs.EUR = Country:newWithSimpleAbbrs{["E"] = "E%s"} -- Europe
 
    abbrevs.GBR = Country:newWithSimpleAbbrs{["A"] = "A%s", ["M"] = "M%s"} -- United Kingdom
 
    abbrevs.GEO = Country:newWithSimpleAbbrs{["A"] = "A %s", ["B"] = "B %s"} -- Georgia
 
    abbrevs.GHA = Country:newWithSimpleAbbrs{["N"] = "N%s", ["R"] = "R%s", ["IR"] = "IR%s"} -- Ghana
 
    abbrevs.GRC = Country:newWithSimpleAbbrs{["A"] = "A%s", ["EO"] = "EO%s"} -- Greece
 
    abbrevs.HKG = Country:newWithSimpleAbbrs{[{"Route", "route"}] = "Route %s"} -- Hong Kong
 
    abbrevs.HRV = Country:newWithSimpleAbbrs{["A"] = "A%s", ["D"] = "D%s"} -- Croatia
 
    abbrevs.HUN = Country:newWithSimpleAbbrs{["M"] = "M%s"} -- Hungary
 
    abbrevs.IDN = Country:newWithSimpleAbbrs{[{"N", "National", "National Highway"}] = "National Route %s"} -- Indonesia
 
    abbrevs.IND = Country:newWithSimpleAbbrs{["NE"] = "NE %s", ["NH"] = "NH %s", ["SH"] = "SH %s"} -- India
 
    abbrevs.ITA = Country:newWithSimpleAbbrs{["A"] = "A%s"} -- Italy
 
    abbrevs.JPN = Country:newWithSimpleAbbrs{[{"National", "Route"}] = "Route %s"} -- Japan
 
    abbrevs.KOR = Country:newWithSimpleAbbrs{[{"National", "NR"}] = "NR %s"} -- South Korea
 
    abbrevs.LKA = Country:newWithSimpleAbbrs{["E"] = "E%s", ["A"] = "A%s", ["B"] = "B%s"} -- Sri Lanka
 
    abbrevs.LVA = Country:newWithSimpleAbbrs{["A"] = "A%s"} -- Latvia
 
    abbrevs.MEX = Country:newWithSimpleAbbrs{[{"Federal Highway", "Hwy", "FH"}] = "Fed. %s", ["SH"] = "SH %s"} -- Mexico
 
    abbrevs.NLD = Country:newWithSimpleAbbrs{["A"] = "A%s", ["N"] = "N%s"} -- Netherlands
 
    abbrevs.NOR = Country:newWithSimpleAbbrs{["National"] = "NR %s", [{"Fylkesvei", "fylkesvei", "Fv", "fv"}] = "Fv %s"} -- Norway
 
    abbrevs.NZL = Country:newWithSimpleAbbrs{["SH"] = "SH %s"} -- New Zealand
 
    abbrevs.POL = Country:newWithSimpleAbbrs{["A"] = "A%s", ["S"] = "S%s", ["DK"] = "DK %s", ["DW"] = "DW %s"} -- Poland
 
    abbrevs.ROU = Country:newWithSimpleAbbrs{["A"] = "A%s", ["DN"] = "DN%s"} -- Romania
 
    abbrevs.RUS = Country:newWithSimpleAbbrs{["M"] = "M%s"} -- Russia
 
    abbrevs.SVK = Country:newWithSimpleAbbrs{["D"] = "D%s", ["R"] = "R%s"} -- Slovakia
 
    abbrevs.SVN = Country:newWithSimpleAbbrs{["A"] = "A%s", ["H"] = "H%s"} -- Slovenia
 
    abbrevs.TUR = Country:newWithSimpleAbbrs{[{"otoyol", "O"}] = "O-%s", [{"state", "D"}] = "D.%s"} -- Turkey
 
    abbrevs.TWN = Country:newWithSimpleAbbrs{[{"NH", "Fwy"}] = "Fwy. %s", ["PH"] = "PH %s"} -- Taiwan
 
    abbrevs.UKR = Country:newWithSimpleAbbrs{["M"] = "Highway M%s", ["H"] = "Highway H%s"} -- Ukraine
 
    abbrevs.URY = Country:newWithSimpleAbbrs{[{"Route", "route"}] = "Route %s"} -- Uruguay
 
    abbrevs.ZAF = Country:newWithSimpleAbbrs{["N"] = "N%s", ["R"] = "R%s", [{"M", "JM"}] = "M%s"} -- South Africa
 
end
 
  
 
function p._abbr(args)
 
function p._abbr(args)
    return abbrevs:abbr(args)
+
return parser(args, 'abbr')
 
end
 
end
  
 
function p.abbr(frame)
 
function p.abbr(frame)
    local pframe = frame:getParent()
+
local args = getArgs(frame)
    local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
+
return p._abbr(args)
    local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
 
   
 
    local function emptyParam(param)
 
        local empty = {[''] = true, ['¬'] = true}
 
        if empty[param] then
 
            return nil
 
        else
 
            return param
 
        end
 
    end
 
   
 
    local country = args.country or config.country
 
    local type = args.type or config.type
 
    local state = args.state or config.state
 
    state = emptyParam(state)
 
    local province = args.province or config.province
 
    province = emptyParam(province)
 
    local route = args.route or config.route
 
    local county = args.county or config.county
 
    local dab = args.dab or config.dab
 
   
 
    return p._abbr{country=country, type=type, state=state, province=province, route=route, county=county, dab=dab}
 
 
end
 
end
  
 
return p
 
return p

Revision as of 06:00, 9 April 2016

Module:Infobox road/abbrev (edit | talk | history | links | watch | logs)


-- Temporary migration module for abbreviations
local p = {}

local getArgs = require('Module:Arguments').getArgs -- Import module function to work with passed arguments
local parserModule = require "Module:Road data/parser" -- DEPLOY: Switch to main module
local parser = parserModule.parser

function p._abbr(args)
	return parser(args, 'abbr')
end

function p.abbr(frame)
	local args = getArgs(frame)
	return p._abbr(args)
end

return p