Jump to content

Module:Infobox road/route and Module:Infobox road/route/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
Fix Linter errors. p tags can't always successfully wrap div tags and other block content. Tested in the sandbox submodules and on the testcases pages; everything worked fine, but revert if I broke anything.
 
Remove p tags with div tags to sync with live version
 
Line 6: Line 6:
local parserModule = require 'Module:Road data/parser'
local parserModule = require 'Module:Road data/parser'
local parser = parserModule.parser
local parser = parserModule.parser
local roadDataModule = require("Module:Road data/sandbox") -- REMOVE SANDBOX

local function banner(args, style)
if args.marker_image then return nil end
local bannerSize
if style == 'small' then
bannerSize = "40px"
else
bannerSize = "72px"
end
local shield = parser(args, 'banner')
local alt = parser(args, 'banner')

if not shield or shield == '' then
return nil
else
return string.format('[[File:%s|%s|alt=%s]]', shield, bannerSize, alt)
end
end




local function shield(args, style)
local function shield(args, style)

if args.marker_image then return args.marker_image end
if args.marker_image then return args.marker_image end
return roadDataModule.shield(args, 'main', style, true)
local horizontalSize
local verticalSize
if style == 'small' then
horizontalSize = "90x40px"
verticalSize = "40x90px"
else
horizontalSize = "154x72px"
verticalSize = "72x154px"
end

local shield = parser(args, 'shieldmain') or parser(args, 'shield') or ''
local label = parser(args, 'name') or parser(args, 'abbr') or ''
local alt = label .. ' marker'
local orientation = parser(args, 'orientation')
local function simpleSize(args)
if orientation and orientation == 'upright' then
return verticalSize
else
return horizontalSize
end
end
local function shield_size(image_name, orientation)
local image = 'File:' .. image_name
local title = mw.title.new(image)

local width = title.file.width
local height = title.file.height
if (orientation and orientation == 'upright') or height > width then
return verticalSize
else
return horizontalSize
end
end
if not shield or shield == '' then
return nil
elseif type(shield) == 'table' then
local res = {}
local sizes = {}
for i,v in ipairs(shield) do
sizes[i] = v
res[i] = string.format('[[File:%s|%s|alt=%s]]', v, shield_size(v), alt)
end
return table.concat(res, ' ')
else
return string.format('[[File:%s|%s|alt=%s]]', shield, simpleSize(args), alt)
end
end
end


Line 95: Line 20:


function p._routeInfo(args)
function p._routeInfo(args)
local style = args.style
local style = args.style
local banner = banner(args, style)
local shield = shield(args, style)
local shield = shield(args, style)
local name = name(args)
local name = name(args)
Line 112: Line 35:
container:tag('div'):cssText('margin:0.1em 0 0 0;'):wikitext(shield)
container:tag('div'):cssText('margin:0.1em 0 0 0;'):wikitext(shield)
else
else
container:tag('div'):cssText('margin:0.1em 0 0 0;'):wikitext(banner)
container:tag('div'):cssText('margin:0 0 0.1em;'):wikitext(shield)
container:tag('div'):cssText('margin:0 0 0.1em;'):wikitext(shield)
container:tag('div'):cssText('margin:0.1em;'):wikitext(name)
container:tag('div'):cssText('margin:0.1em;'):wikitext(name)
Line 126: Line 48:


function p._shields(args)
function p._shields(args)
local style = args.style
local style = args.style
local banner = banner(args, style)
local shield = shield(args, style)
local shield = shield(args, style)


if not args.type and not args.route and not args.name and not args.marker_image then
if not args.type and not args.route and not args.name and not args.marker_image then
local container = nil
local container = nil
else
else local container = mw.html.create('div'):cssText('text-align:center; display: inline-block; vertical-align: baseline; line-height: 0;')
container:tag('div'):cssText('margin:0.1em 0 0 0;'):wikitext(banner)
local container = mw.html.create('div'):cssText('text-align:center; display: inline-block; vertical-align: baseline; line-height: 0;')
container:tag('div'):cssText('margin:0 0 0.1em;'):wikitext(shield)
container:tag('div'):cssText('margin:0 0 0.1em;'):wikitext(shield)
return tostring(container)
return tostring(container)
end
end
end
end