Modul:HK-MTR stations

Dari Wikipedia bahasa Indonesia, ensiklopedia bebas

local getArgs = require('Modul:Arguments').getArgs
local data = mw.loadData('Modul:HK-MTR stations/data')

local p = {}

local function makeInvokeFunction(funcName)
	-- makes a function that can be returned from #invoke, using
	-- [[Modul:Arguments]].
	return function (frame)
		local args = getArgs(frame, {parentOnly = true})
		return p[funcName](args)
	end
end

p.station = makeInvokeFunction('_station')

local function errorText(message)
	return '<strong class="error">' .. message .. '</strong>'
end

local function getStation(code)
	local station = data.stations[code]
	if not station then
		local alias = data.aliases[code]
		if alias then
			code = alias
			station = data.stations[code]
		end
	end
	-- The returned code is what should be used (target of any alias).
	return station, code
end

function p._station(args)
	local code = args[1] or args.station  -- arguments have been trimmed
	if code == nil or code == '' then
		return errorText('Need station or stop name')
	end
	local station, code = getStation(code)
	local link, text, result
	if station then
		if station.link==nil then
			return station.text
			else link = station.link or code
		end
		text = station.text or code
	else
		link = 'Stasiun ' .. code
		text = code
	end
	result = '[[' .. link .. '|' .. text .. ']]'
	return result
end

return p