模組:沙盒/TimWu007/MTR

维基百科,自由的百科全书
文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

直接包含本模塊的模板有:

用法

{{HK-MTR color|Tuen Ma Line}} #
{{HK-MTR color|屯馬}} #9a3b26
{{HK-MTR color|無意義}} #
{{HK-MTR icon|屯馬}} Template:HK-MTR icon
{{HK-MTR icon|港島線}} Template:HK-MTR icon
{{HK-MTR icon|lrt}} Template:HK-MTR icon
{{HK-MTR icon|東|沙田站}} Template:HK-MTR icon
{{HK-MTR icon|WR-KCR|3=西鐵綫以前由九廣鐵路經營}} Template:HK-MTR icon
{{HK-MTR icon|荃|太子站|跨月台轉車站}} Template:HK-MTR icon

數據表

模塊承認的路綫簡稱值及其代表顏色的RGB值見module:MTR/data


Category:香港鐵路模板

local getArgs = require('Module:Arguments').getArgs
local data = mw.loadData('Module:MTR/data')
 
local p = {}
 
local function makeInvokeFunction(funcName)
	-- makes a function that can be returned from #invoke, using
	-- [[Module:Arguments]].
	return function (frame)
		local args = getArgs(frame, {parentOnly = true})
		return p[funcName](args)
	end
end
 
local function getColor(code)
	return data.colors[code] or '000'
end
 
p.colorbyname = makeInvokeFunction('_colorbyname')
 
function p._colorbyname(args)
	local code = args[1] or ''
	code = code:upper()
	return getColor(code)
end
 
p.icon = makeInvokeFunction('_icon')
 
function p._icon(args)
	-- Retrieve arguments
	local code = args[1] or ''
	local link = args[2] or args.link
	local text = args[3] or args.text
 
	-- Fetch data from the data module
	code = code:upper() -- Convert to upper case
	local name = data.names[code]
	if not name then
		-- If we didn't find a name corresponding to the code, exit with a wikitext error.
		return '<strong class="error">Error: "' .. tostring(code) .. '" is not a valid code.</strong>'
	end
	local color = getColor(code)
 
	-- Format the link name
	link = link or name
	if data.needs_dab[link] then
		link = '香港' .. link -- 後備迴避歧義用參數,儘管在中文維基百科用不上,如有必要請到模塊:MTR/data修改。
	end
 
	-- Format the text
	text = text or name .. '轉車站'
 
	-- Build the link
	return '[[' .. link .. '|<span title="' .. text .. '" style="color:#' .. color .. ';font-size:120%">█</span>]]'
end
 
return p