Module:MTR
From EverybodyWiki Bios & Wiki
Text style and color scheme lua module for the Hong Kong MTR related articles. It is invoked by templates {{HK-MTR color}}, {{HK-MTR icon}}, {{HK-MTR lines}}, {{HK-MTR box}} and {{HK-MTR box1}}.
Usage
| Color | |
|---|---|
{{HK-MTR color|Ma On Shan Line}} |
923011 |
{{HK-MTR color|MOS}} |
923011 |
{{HK-MTR color|Gibberish}} |
000 |
| Icon | |
{{HK-MTR icon|MOS}} |
|
{{HK-MTR icon|IS}} |
|
{{HK-MTR icon|lrt}} |
|
{{HK-MTR icon|AEL}} |
|
{{HK-MTR icon|615P}} |
615P |
{{HK-MTR icon|North South|link=Sha Tin Station}} |
|
{{HK-MTR icon|WR-KCR|text=West Rail Line was previously operated by KCRC}} |
|
{{HK-MTR icon|TW|link=Prince Edward Station (MTR)|text=Cross-platform interchange station}} |
|
| Lines | |
{{HK-MTR lines|siw}} |
South Island line (West) |
{{HK-MTR lines|kt|MTR}} |
Kwun Tong line |
{{HK-MTR lines|nl|3=Gibberish}} |
Gibberish |
| Box | |
{{HK-MTR box|sie}} |
South Island line |
{{HK-MTR box|tko|MTR}} |
Tseung Kwan O line |
{{HK-MTR box|tc|3=Gibberish}} |
Gibberish |
{{HK-MTR box1|ae}} |
Airport Express |
{{HK-MTR box1|wrl|MTR}} |
West Rail line |
{{HK-MTR box1|ewc|3=Under construction}} |
Under construction |
Data
The module's data can be found at Module:MTR/data.
| This template is used by the rail succession box templates. Other related templates in this set are: |
-- This module implements {{HK-MTR icon}}, {{HK-MTR color}}, {{HK-MTR lines}} and {{HK-MTR box}}.
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
local function getTextcolor(code)
return data.textcolors[code] or '000'
end
p.colorbyname = makeInvokeFunction('_colorbyname')
function p._colorbyname(args)
local code = args[1] or ''
code = code:upper()
return getColor(code)
end
local function getLink(code)
local name = data.names[code]
link = name
if data.link[name] then
link = data.link[name]
elseif data.needs_dab[name] then
link = link .. ' (MTR)'
elseif data.lr[name] then
link = 'MTR Light Rail Route ' .. link
end
return link
end
local function invalid(code)
return '<strong class="error">Error: "' .. tostring(code) .. '" is not a valid code.</strong>'
end
p.link = makeInvokeFunction('_link')
function p._link(args)
-- Retrieve arguments
local code = args[1] or ''
code = code:upper() -- Convert to upper case
if not code then
return invalid(code)
end
return getLink(code)
end
p.icon = makeInvokeFunction('_icon')
function p._icon(args)
local code = args[1] or ''
local link = args[2] or args.link
local text = args[3] or args.text
code = code:upper()
local color = getColor(code)
link = link or getLink(code)
local name = data.names[code]
if not name then
return invalid(code)
end
-- Format the text
if text == noint then
text = name
else
text = text or 'Interchange station for the ' .. name
end
-- Build the link
local lr = data.lr[code]
if lr then
local textcolor = getTextcolor(code)
if link ~= '' then return '<span style="background-color:#' .. color .. '; border:1px solid #' .. color .. ';"> [['.. link ..'|<span style="color:#' .. textcolor .. '; font-weight:bold; font-size:inherit; white-space:nowrap;">' .. name .. '</span>]] </span>' end
return '<span style="background-color:#' .. color .. '; border:1px solid #' .. color .. ';"> <span style="color:#' .. textcolor .. '; font-weight:bold; font-size:inherit; white-space:nowrap;">' .. name .. '</span> </span>'
else
return '[[' .. link .. '|<span title="' .. text .. '" style="background-color:#' .. color .. '; border:1px solid #000; text-align:center;"> </span>]]'
end
end
p.line = makeInvokeFunction('_line')
function p._line(args)
local code = args[1] or ''
local link = args[2] or args.link
local text = args[3] or args.text
code = code:upper()
link = link or getLink(code)
local name = data.names[code]
if not name then
return invalid(code)
end
text = text or name
if link ~= '' then return '[[' .. link .. '|' .. text .. ']]' end
return text
end
p.box = makeInvokeFunction('_box')
function p._box(args)
local code = args[1] or ''
local link = args[2] or args.link
local text = args[3] or args.text
code = code:upper()
local color = getColor(code)
link = link or getLink(code)
local name = data.names[code]
if not name then
return invalid(code)
end
text = text or name
if link ~= '' then return '<span title="' .. text .. '" style="background-color:#' .. color .. '; border:1px solid #000; text-align:center;"> </span> [[' .. link .. '|' .. text .. ']]' end
return '<span title="' .. text .. '" style="background-color:#' .. color .. '; border:1px solid #000; text-align:center;"> </span> '..text
end
p.box1 = makeInvokeFunction('_box1')
function p._box1(args)
local code = args[1] or ''
local link = args[2] or args.link
local text = args[3] or args.text
code = code:upper()
local color = getColor(code)
link = link or getLink(code)
local name = data.names[code]
if not name then
return invalid(code)
end
text = text or name
return '<span style="display:inline-block; width:1.5em; height:1.5em; margin:1px 0; border:1px solid #000; background-color:#' .. color .. '; text-align:center;"> </span> [[' .. link .. '|' .. text .. ']]'
end
return p
