Jump to content

Module:Road data/routelist and Module:Road data/routelist/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
adj
 
Initial adjustments
 
Line 15: Line 15:
local parser = parserModule.parser
local parser = parserModule.parser
local util = require("Module:Road data/util")
local util = require("Module:Road data/util")
local sizeModule = require("Module:Road data/size").size({style = "test"})


-- Shields
-- Shields
local defaultShieldSize = 30
local defaultShieldSize = 32


local function addContextBanner(route, name, suffix, bannerSpec)
local function addContextBanner(route, name, suffix, bannerSpec)
Line 39: Line 38:
end
end
if shield and shield ~= '' then
if shield and shield ~= '' then
local shieldSize = sizeModule
local shieldSize = defaultShieldSize
-- Add banner plate.
-- Add banner plate.
insert(bannerSpec, {shield, shieldSize})
insert(bannerSpec, {shield, shieldSize})
Line 78: Line 77:
local function size(route)
local function size(route)
if orientation == "upright" then
if orientation == "upright" then
return sizeModule
return defaultShieldSize
else return "x" .. sizeModule
else return "x" .. defaultShieldSize
end
end
end
end
Line 86: Line 85:
local banner = parser(route, 'banner') or {}
local banner = parser(route, 'banner') or {}
local bannersize = sizeModule
local bannersize = defaultShieldSize
local bannersuffix = parser(route, 'bannersuffix')
local bannersuffix = parser(route, 'bannersuffix')


Line 123: Line 122:
local missingShields
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 == nil then
local file = mw.title.new(shield, 'Media').file
-- Cache result.
local exists = file.exists
result = {exists}
if exists then result[2] = file.width >= file.height end
shieldExistsCache[shield] = result
end
if result[1] then return true, result[2] end
insert(missingShields, shield)
return false
end


local function render(shieldEntry, scale, showLink)
local function render(shieldEntry, scale, showLink)
Line 173: Line 152:
shieldCode = format("[[File:%s|%spx|link=|alt=]]<br>%s",
shieldCode = format("[[File:%s|%spx|link=|alt=]]<br>%s",
banner[1],
banner[1],
banner[2],
defaultShieldSize,
shieldCode)
shieldCode)
end
end