Bước tới nội dung

Mô đun:Road data/browse

Bách khoa toàn thư mở Wikipedia
local p = {}local getArgs = require('Mô đun:Arguments').getArgs -- Import module function to work with passed argumentslocal parserModule = require "Mô đun:Road data/parser"local parser = parserModule.parserlocal function size(args)	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'endlocal function shield(args)	local size = size(args)	local shield = parser(args, 'shield')	if not shield or shield == '' then return '' end	return string.format("[[Tập tin:%s|%spx|link=|alt=]]", shield, size)endlocal function link(args)	local abbr = parser(args, 'abbr')	if not abbr then		local page = mw.title.getCurrentTitle().prefixedText -- Get transcluding page's title		return mw.ustring.format("<span class=\"error\">Loại không hợp lệ: %s</span>[[Thể loại:Infobox road transclusion errors|& %s]]", args.type, page)	end	local link = parser(args, 'link')	if not link or link == '' then		return mw.ustring.format("<span class=\"nowrap\">%s</span>", abbr)	else		return mw.ustring.format("<span class=\"nowrap\">[[%s|%s]]</span>", link, abbr)	endendlocal 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 cellendlocal function nextRoute(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"] = "right"} )	cell:wikitext(linkText .. ' ' .. shieldText .. " →")	return cellendfunction p._browse(args)	local browseRow = mw.html.create('tr')		local country = args.country	local state = args.state or args.province	local county = args.county		local previousData = {country = country, state = state, county = county,	                      type = args.previous_type, route = args.previous_route,	                      dab = args.previous_dab}	local nextData = {country = country, state = state, county = county,	                  type = args.next_type, route = args.next_route,	                  dab = args.next_dab}		local previousRoute = previousRoute(previousData)	local nextRoute = nextRoute(nextData)		local centerRoute = mw.html.create('td'):css( {["text-align"] = "center", ["white-space"] = "nowrap", width = "10%", ["vertical-align"] = "middle", padding = "0"} )	local route = args.browse_route	if route then		centerRoute:wikitext("'''" .. route .. "'''")	end		browseRow:node(previousRoute):node(centerRoute):node(nextRoute)	return tostring(browseRow)endfunction p.browse(frame)	local args = getArgs(frame)	args.browse_route = args.route	return p._browse(args)endreturn p