Module:Road data/browse

local p = {}

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

local function routeText(route)
	local shieldText = roadDataModule.shield(route, nil, nil, nil, true)
	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({
		["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",
		["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",
		["padding-left"] = "3px",
		["padding-right"] = "3px"
	})
	local route = route.browse_route
	if route then
		centerRoute:css("padding-left", "6px")
		centerRoute:css("padding-right", "6px")
		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

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.