跳转到内容

模組:香港巴士

本页使用了标题或全文手工转换
被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由LuciferianThomas留言 | 贡献2021年7月25日 (日) 12:05 (attempt 1)编辑。这可能和当前版本存在着巨大的差异。

-- placeholder for subpage, will be written later
-- rewrite {{九龍新界巴士簡單列表}} etc. into module to reduce load
local getArgs = require('Module:Arguments').getArgs
local alldata = {
	klnt = require('Module:香港巴士/klnt');
	hki = require('Module:香港巴士/hki');
	crh = require('Module:香港巴士/crh');
	lantau = require('Module:香港巴士/lantau');
	aex = require('Module:香港巴士/aex')
}
local p = {}

local dir = {'↺','→','⇄','→<br/>←','↺<br/>←','→<br/>↺'}

function split(inputstr, sep)
        if sep == nil then
                sep = "%s"
        end
        local t={}
        for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
                table.insert(t, str)
        end
        return t
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	local grp = '|-\n| style="text-align: right; padding-right: 10px" |'
	if args[1] == "klnt" or args[1] == "九龍" or args[1] == "新界" or args[1] == "九龍新界" then grp = "klnt"
	elseif args[1] == "hki" or args[1] == "港島" or args[1] == "香港島" then grp = "hki"
	elseif args[1] == "crh" or args[1] == "過海" then grp = "crh"
	elseif args[1] == "lantau" or args[1] == "大嶼山" then grp = "lantau"
	elseif args[1] == "aex" or args[1] == "機場" then grp = "aex"
	end
	local data = alldata[grp]
	local out = ""
	-- Main module code goes here.
	for i = 1, table.getn(args), 1 do
		out = out .. args[i]
		if data[args[i]] then
			out = out .. '\n| style="text-align: right; white-space: nowrap" | '
			local special = string.find('' .. args[i], "_s")
			if special then
				out = out .. data[args[i]]['special' .. split(args[i], "_s")[2] .. '_endpoint1']
						  .. '\n| style="text-align: center; padding: 0px 8px 0px 8px" |'
						  .. dir[data[args[i]]['special' .. split(args[i], "_s")[2] .. '_direction']+1]
						  .. '\n| style="white-space: nowrap" |'
						  .. data[args[i]]['special' .. split(args[i], "_s")[2] .. '_endpoint2']
						  .. '\n| style="padding-left: 10px" |'
						  .. data[args[i]]['special' .. split(args[i], "_s")[2] .. '_status']
			else
				out = out .. data[args[i]]['endpoint1']
						  .. '\n| style="text-align: center; padding: 0px 8px 0px 8px" |'
						  .. dir[data[args[i]]['direction']+1]
						  .. '\n| style="white-space: nowrap" |'
						  .. data[args[i]]['endpoint2']
						  .. '\n| style="padding-left: 10px" |'
						  .. data[args[i]]['status']
			end
		else
			out = out .. '\n| colspan="3" style="text-align: center" | (沒有資料)'
		end
	end
	return out
end

return p