Jump to content

Module:Road data/browse/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Add back width
Undid revision 1043788859 by BrandonXLF (talk) Center route must always be present
Line 5: Line 5:


local function routeText(route)
local function routeText(route)
local shieldText = roadDataModule.shield(route, nil, nil, nil, true)
local shieldText = roadDataModule.shield(route)
local linkText = roadDataModule.link(route)
local linkText = roadDataModule.link(route)
local result = mw.html.create("span"):css({display = "inline-block"})
local result = mw.html.create("span"):css({display = "inline-block"})
Line 14: Line 14:
local function previousRoute(route)
local function previousRoute(route)
local cell = mw.html.create('td'):css({
local cell = mw.html.create('td'):css({
width = "50%",
width = "45%",
padding = "0",
padding = "0",
["vertical-align"] = "middle",
["vertical-align"] = "middle",
Line 30: Line 30:
local cell = mw.html.create('td'):css({
local cell = mw.html.create('td'):css({
direction = "rtl",
direction = "rtl",
width = "50%",
width = "45%",
padding = "0",
padding = "0",
["vertical-align"] = "middle",
["vertical-align"] = "middle",
Line 59: Line 59:
}
}
local browseRow = mw.html.create('tr')
local previousRoute = previousRoute(previousData)
local nextRoute = nextRoute(nextData)

if previousData.typeerror or nextData.typeerror then
browseRow:node(previousRoute(previousData))
route.typeerror = true

end
local centerRoute = mw.html.create('td'):css({
["text-align"] = "center",
["white-space"] = "nowrap",
["vertical-align"] = "middle",
padding = "0"
})
local route = route.browse_route
local route = route.browse_route
if route then
if route then
centerRoute:wikitext(format("'''%s'''", route))
browseRow:node(mw.html.create('td'):css({
["text-align"] = "center",
["white-space"] = "nowrap",
["vertical-align"] = "middle",
padding = "0"
}):wikitext(format("'''%s'''", route)))
end
end
browseRow:node(nextRoute(nextData))
local browseRow = mw.html.create('tr')
browseRow:node(previousRoute):node(centerRoute):node(nextRoute)
if previousData.typeerror or nextData.typeerror then
route.typeerror = true
end

return tostring(browseRow)
return tostring(browseRow)
end
end

Revision as of 00:46, 12 September 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",
		["vertical-align"] = "middle",
		["text-align"] = "left"
	})
	if not route.type or route.type == '' then
		cell:wikitext(" ")
	else
		cell:wikitext("← " .. routeText(route))
	end
	return cell
end

local function nextRoute(route)
	local cell = mw.html.create('td'):css({
		direction = "rtl",
		width = "45%",
		padding = "0",
		["vertical-align"] = "middle",
		["text-align"] = "right"
	})
	if not route.type or route.type == '' then
		cell:wikitext(" ")
	else
		cell:wikitext("→ " .. routeText(route))
	end
	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",
		["vertical-align"] = "middle",
		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