Jump to content

Module:Infobox road/route: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
pokity
(One intermediate revision by the same user not shown)
Line 9: Line 9:
local parserModule = require "Module:Road data/parser"
local parserModule = require "Module:Road data/parser"
local parser = parserModule.parser
local parser = parserModule.parser
local shieldSize = require("Module:Road data/size")._size({style = 'infobox'})
local bannerSize = require("Module:Road data/size")._banner({style = 'infobox'})


local function banner(args, frame)
local function banner(args, bannerSize)
local firstSize, secondSize = bannerSize
local firstSize, secondSize = bannerSize
local shield, second = parser(args, 'banner')
local shield, second = parser(args, 'banner')
Line 36: Line 34:
end
end


local function shield(args, frame)
local function shield(args, shieldSize)
local function source(args)
local function source(args)
if args.type == 'Dual' or args.type == 'Both' then
if args.type == 'Dual' or args.type == 'Both' then
Line 76: Line 74:


function p._routeInfo(args) -- Throws an invalid nil type error when none of the shield/type/route/name parameters are called
function p._routeInfo(args) -- Throws an invalid nil type error when none of the shield/type/route/name parameters are called
local banner = banner(args)
local shield = shield(args)
local style = args.style
local banner = banner(args, require("Module:Road data/size")._banner({style = style}))
local shield = shield(args, require("Module:Road data/size")._size({style = style}))
local name = name(args)
local name = name(args)

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

Revision as of 06:41, 15 February 2021

local p = {} 

local format = mw.ustring.format
local insert = table.insert
local concat = table.concat
require('Module:No globals')
--local roadDataModule = require("Module:Road data")
local getArgs = require('Module:Arguments').getArgs	
local parserModule = require "Module:Road data/parser"
local parser = parserModule.parser

local function banner(args, bannerSize)
	local firstSize, secondSize = bannerSize
	local shield, second = parser(args, 'banner')
	if not shield or shield == '' then
		return nil
	elseif type(shield) == 'table' then
		shield, second = shield[1], shield[2]
	end
	local alt = parser(args, 'banner')
	local function render(shield, size)
		local size = bannerSize
		if args.shielderr then
			return nil
		else return string.format("[[File:%s|%s|alt=%s]]", shield, size, alt)
		end
	end
	local rendered = render(shield, firstSize)
	if second and type(second) == 'string' then
		local size = secondSize or firstSize
		rendered = rendered .. render(second, size)
	end
	return rendered
end

local function shield(args, shieldSize)
	local function source(args)
		if args.type == 'Dual' or args.type == 'Both' then
		return parser(args, 'shield')
			else return parser(args, 'shieldmain') or parser(args, 'shield')
		end
	end
	local label = parser(args, 'name') or parser(args, 'abbr')
	if args.marker_image then return args.marker_image
		else
	local firstSize, secondSize = shieldSize
	local shield, second = source(args)
	if not shield or shield == '' then
		return nil
	elseif type(shield) == 'table' then
		shield, second = shield[1], shield[2]
	end
	local alt = label .. " marker"
	local function render(shield, size)
		if args.shielderr then
			return nil
		else return string.format("[[File:%s|%s|%s]]", shield, size, alt)
		end
	end
	local rendered = render(shield, firstSize)
	if second and type(second) == 'string' then
		local size = secondSize or firstSize
		rendered = rendered .. render(second, size)
	end
	return rendered
	end
end

-- Links/abbreviations
local function name(args)
	local name = args.name or parser(args, 'name') or parser(args, 'abbr')
	return name
end

function p._routeInfo(args) -- Throws an invalid nil type error when none of the shield/type/route/name parameters are called
	
	local style = args.style
	local banner = banner(args, require("Module:Road data/size")._banner({style = style}))
	local shield = shield(args, require("Module:Road data/size")._size({style = style}))
	local name = name(args)

	if not args.type and not args.route and not args.name and not args.marker_image then
		local container = nil
	else local container = mw.html.create('div'):cssText("width:100%; text-align:center; background:none; border-collapse:collapse;")
			container:tag('p'):wikitext('')
		if args.marker_image == 'none' or args.name and not args.marker_image and not args.type and not args.route then 
			container:tag('p'):cssText("margin:0.1em;"):wikitext(name)
		elseif args.marker_image ~= '' and args.name == '' or args.name == nil and not args.type and not args.route then
			container:tag('p'):cssText("margin:0.25em 0.1em;"):wikitext(shield)
		elseif args.country == 'AUS' then
			container:tag('p'):cssText("margin:0.1em;"):wikitext(name)
			container:tag('p'):cssText("margin:0.25em 0.1em;"):wikitext(shield)
		elseif parser(args, 'banner') == '' or parser(args, 'banner') == nil then
			container:tag('p'):cssText("margin:0.25em 0.1em;"):wikitext(shield)
			container:tag('p'):cssText("margin:0.1em;"):wikitext(name)
		else
			container:tag('p'):cssText("margin:0.25em 0.1em 0 0.1em;"):wikitext(banner)
			container:tag('p'):cssText("margin:0 0.1em 0.25em 0.1em;"):wikitext(shield)
			container:tag('p'):cssText("margin:0.1em;"):wikitext(name)
		end
		return tostring(container)
	end
end

function p.routeInfo(frame)
	local args = getArgs(frame)
	return p._routeInfo(args);
end

return p