Jump to content

Module:Road data/browse: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
this might work
sandbox to main
Line 1: Line 1:
local p = {}
local p = {}
local getArgs = require('Module:Arguments').getArgs -- Import module function to work with passed arguments
local parserModule = require "Module:Road data/parser"
local parser = parserModule.parser


local function size(args)
local format = mw.ustring.format
local roadDataModule = require("Module:Road data")
local country = args.country
local state = args.state or args.province
local type = args.type
if country == 'MEX' then
return "20x30"
elseif country == 'CAN' then
if state == 'AB' or state == 'QC' or state == 'SK' then
return "20x30"
elseif state == 'NS' then
if (type == 'NS' or type == 'Hwy') then
return "18"
else
return "x20"
end
elseif state == 'ON' then
if type == 'ON' or type == 'Hwy' or type == 'Fwy' then
return "20x30"
elseif type == 'CR' or type == 'RR' then
return "30x32"
end
end
return "25x20"
elseif country == 'USA' then
if state == 'NY' and (type == 'NY 1927' or type == 'NY 1948') then
return '20'
end
end
return 'x20'
end


local function shield(args)
local function routeText(route)
local size = size(args)
local shieldText = roadDataModule.shield(route)
local shield = parser(args, 'shield')
local linkText = roadDataModule.link(route)
local result = mw.html.create("span"):css({display = "inline-block"})
if not shield or shield == '' then return '' end
result:wikitext(shieldText .. ' ' .. linkText)
return string.format("[[File:%s|%spx|link=|alt=]]", shield, size)
return tostring(result)
end
end


local function link(args)
local function previousRoute(route)
local abbr = parser(args, 'abbr')
local cell = mw.html.create('td'):css({
width = "45%",
if not abbr then
padding = "0",
local page = mw.title.getCurrentTitle().prefixedText -- Get transcluding page's title
["text-align"] = "left"
return string.format("<span class=\"error\">Invalid type: %s</span>[[Category:Infobox road transclusion errors|& %s]]", args.type, page)
end
})
cell:wikitext("← " .. routeText(route))
local link = parser(args, 'link')
if not link or link == '' then
return string.format("<span class=\"nowrap\">%s</span>", abbr)
else
return string.format("<span class=\"nowrap\">[[%s|%s]]</span>", link, abbr)
end
end

local function previousRoute(args)
local shieldText = shield(args)
local linkText = link(args)
local cell = mw.html.create('td'):css( {width = "45%", ["vertical-align"] = "middle", padding = "0", ["text-align"] = "left"} )
cell:wikitext("← " .. shieldText .. ' ' .. linkText)
return cell
return cell
end
end


local function nextRoute(args)
local function nextRoute(route)
local shieldText = shield(args)
local cell = mw.html.create('td'):css({
direction = "rtl",
local linkText = link(args)
width = "45%",
local cell = mw.html.create('td'):css( {width = "45%", ["vertical-align"] = "middle", padding = "0", ["text-align"] = "right"} )
padding = "0",
cell:wikitext(linkText .. ' ' .. shieldText .. " →")
["text-align"] = "right"
})
cell:wikitext("→ " .. routeText(route))
return cell
return cell
end
end


function p._browse(args)
function p._browse(route)
local browseRow = mw.html.create('tr')
local country = route.country
local state = route.state or route.province
local county = route.county
local country = args.country
local previousData = {
local state = args.state or args.province
country = country, state = state, county = county,
type = route.previous_type, route = route.previous_route,
local county = args.county
dab = route.previous_dab
}
local previousData = {country = country, state = state, county = county,
local nextData = {
type = args.previous_type, route = args.previous_route,
country = country, state = state, county = county,
dab = args.previous_dab}
type = route.next_type, route = route.next_route,
local nextData = {country = country, state = state, county = county,
dab = route.next_dab
type = args.next_type, route = args.next_route,
}
dab = args.next_dab}
local previousRoute = previousRoute(previousData)
local previousRoute = previousRoute(previousData)
local nextRoute = nextRoute(nextData)
local nextRoute = nextRoute(nextData)
if previousData.typeerror or nextData.typeerror then
route.typeerror = true
end
local centerRoute = mw.html.create('td'):css( {["text-align"] = "center", ["white-space"] = "nowrap", width = "10%", ["vertical-align"] = "middle", padding = "0"} )
local centerRoute = mw.html.create('td'):css({
["text-align"] = "center",
["white-space"] = "nowrap",
width = "10%",
padding = "0"
})
local route = args.browse_route
local route = route.browse_route
if route then
if route then
centerRoute:wikitext("'''" .. route .. "'''")
centerRoute:wikitext(format("'''%s'''", route))
end
end
local browseRow = mw.html.create('tr')
browseRow:node(previousRoute):node(centerRoute):node(nextRoute)
browseRow:node(previousRoute):node(centerRoute):node(nextRoute)
return tostring(browseRow)
return tostring(browseRow)
Line 100: Line 72:


function p.browse(frame)
function p.browse(frame)
-- Import module function to work with passed arguments
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
local args = getArgs(frame)
args.browse_route = args.route
args.browse_route = args.route

Revision as of 03:23, 5 February 2021

local p = {}

local format = mw.ustring.format
local roadDataModule = require("Module:Road data")

local function routeText(route)
	local shieldText = roadDataModule.shield(route)
	local linkText = roadDataModule.link(route)
	local result = mw.html.create("span"):css({display = "inline-block"})
	result:wikitext(shieldText .. ' ' .. linkText)
	return tostring(result)
end

local function previousRoute(route)
	local cell = mw.html.create('td'):css({
		width = "45%",
		padding = "0",
		["text-align"] = "left"
	})
	cell:wikitext("← " .. routeText(route))
	return cell
end

local function nextRoute(route)
	local cell = mw.html.create('td'):css({
		direction = "rtl",
		width = "45%",
		padding = "0",
		["text-align"] = "right"
	})
	cell:wikitext("→ " .. routeText(route))
	return cell
end

function p._browse(route)
	local country = route.country
	local state = route.state or route.province
	local county = route.county
	
	local previousData = {
		country = country, state = state, county = county,
		type = route.previous_type, route = route.previous_route,
		dab = route.previous_dab
	}
	local nextData = {
		country = country, state = state, county = county,
		type = route.next_type, route = route.next_route,
		dab = route.next_dab
	}
	
	local previousRoute = previousRoute(previousData)
	local nextRoute = nextRoute(nextData)
	if previousData.typeerror or nextData.typeerror then
		route.typeerror = true
	end
	
	local centerRoute = mw.html.create('td'):css({
		["text-align"] = "center",
		["white-space"] = "nowrap",
		width = "10%",
		padding = "0"
	})
	local route = route.browse_route
	if route then
		centerRoute:wikitext(format("'''%s'''", route))
	end
	
	local browseRow = mw.html.create('tr')
	browseRow:node(previousRoute):node(centerRoute):node(nextRoute)
	return tostring(browseRow)
end

function p.browse(frame)
	-- Import module function to work with passed arguments
	local getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame)
	args.browse_route = args.route
	return p._browse(args)
end

return p