-- Sandbox, do not deletelocal p =
local concat = table.concatlocal insert = table.insertlocal format = mw.ustring.formatlocal trim = mw.text.trim
local parserModule = require("Module:Road data/parser")local parser = parserModule.parserlocal util = require("Module:Road data/util")local sizeModule = require("Module:Road data/size/sandbox") -- REMOVE SANDBOX
-- Shieldslocal defaultShieldSize = 24
local function addContextBanner(route, name, suffix, bannerSpec, sizeStyle) local bannerModule = 'Module:Road data/banners/' .. string.upper(route.country) local shieldfield = name .. 'shield' local shield = parser(route, shieldfield) if shield
nil then suffix = parser(route, 'shield', 'suffix', bannerModule) end if suffix and suffix ~= then shield = shield .. " " .. suffix end shield = shield .. ".svg" end end if shield and shield ~= then local shieldSize = sizeModule._size -- Add banner plate. insert(bannerSpec,) endend
local function bannerSpec(banner, bannerSize, bannerSuffix, route, sizeStyle) local banners = if type(banner)
if route.dir then addContextBanner(route, 'dir', bannerSuffix, banners, sizeStyle) end if route.to then addContextBanner(route, 'to', bannerSuffix, banners, sizeStyle) end
return bannersend
local function shieldSpec(route, shieldStyle, sizeStyle) local shieldSpec =
local shield if route.to then shield = parser(route, 'shieldto') end if not shield and shieldStyle
'list' then shield = parser(route, 'shieldlist') end if not shield then shield = parser(route, 'shield') or end
if shield
local orientation = parser(route, 'orientation') local shieldsize = sizeModule._size local banner = parser(route, 'banner') or local bannersize = sizeModule._size local bannersuffix = parser(route, 'bannersuffix')
local bannerIsNotTable = type(banner) ~= "table" local bannersizeIsNotTable = type(bannersize) ~= "table" local bannersuffixIsNotTable = type(bannersuffix) ~= "table"
if type(shield)
"" then size = nil end -- banner.all describes banners that apply to all multiple shields. local shieldBanner = bannerIsNotTable and banner or (banner[i] or banner.all or) -- Banner size is default if the corresponding entry -- in bannerSize table is not set. local shieldBannerSize = bannersizeIsNotTable and bannersize or (bannersize[i] or bannersize.all or defaultShieldSize) local shieldBannerSuffix = bannersuffix and (bannersuffixIsNotTable and bannersuffix or bannersuffix[i]) insert(shieldSpec,) end elseif shield ~= then if shieldsize
return shieldSpecend
local missingShields
local shieldExistsCache =
-- Return up to two booleans.-- The first boolean is false if `shield` does not exist, and true otherwise.-- If the first boolean is true, the second boolean is true if the shield is-- landscape (width >= height), and false otherwise.local function shieldExists(shield) local result = shieldExistsCache[shield] if result
local function render(shieldEntry) local shield = shieldEntry.shield local banners = shieldEntry.banners
local shieldCode = format("", shield[1], shield[2]) if not banners[1] then return shieldCode end
for _,banner in ipairs(banners) do shieldCode = format("
%s", banner[1], banner[2], shieldCode) end return '
function p.shield(route, shieldStyle, sizeStyle) missingShields =
local rendered = for _,entry in ipairs(shieldSpec(route, shieldStyle, sizeStyle)) do insert(rendered, render(entry)) end return concat(rendered), missingShieldsend
function p.link(route) local abbr, errMsg = parser(route, 'abbr') if not abbr then route.typeerror = true return util.err(errMsg or format("Invalid type: %s", route.type or "(nil)")) end if route.nolink then return abbr, abbr end
local link = parser(route, 'link') or if link
return format("%s", link, abbr), abbrend
return p