local p = {}
local getArgs = require('Module:Arguments').getArgs
local function makeInvokeFunction(funcName)
return function(frame)
local args = getArgs(frame, { parentOnly = true })
return p[funcName](args, frame)
end
end
local _data = require('Module:Adjacent stations/重庆轨道交通')
local _color = require('Module:Adjacent stations')._color
local function getColor(line, name)
return '#' .. _color({ '重庆轨道交通', line, data = _data })
end
local makeList = require('Module:list').makeList
local has_photo = false
function p._exit_list(args, frame)
local lines = mw.text.split(mw.text.trim(args[1]), '\n')
local rows = {}
local any_closed = false
local unknown_args = false
for i, line in ipairs(lines) do
local props = mw.text.split(line, ';')
rows[i] = {}
rows[i]['index'] = mw.text.trim(props[1])
rows[i]['line'] = mw.text.trim(props[2] or '')
if props[2] and props[2] ~= '' then
rows[i]['rowspan'] = 1
end
rows[i]['tags'] = mw.text.trim(props[3] or '')
rows[i]['loc'] = mw.text.trim(props[4] or '')
rows[i]['targets'] = mw.text.split(mw.text.trim(props[5] or ''), ',')
if props[6] and mw.text.trim(props[6]) ~= '' then
rows[i]['photo'] = mw.text.trim(props[6])
has_photo = true
end
rows[i]['ref'] = mw.text.trim(props[7] or '')
end
for i = #rows - 1, 1, -1 do
if rows[i].line and rows[i].line ~= '' and rows[i].line == rows[i + 1].line then
rows[i].rowspan = rows[i].rowspan + rows[i + 1].rowspan
rows[i + 1].rowspan = 0
end
end
for i, row in ipairs(rows) do
local result = { '|-' }
if mw.ustring.find(row.tags, 'c') then
table.insert(result, ' style="background-color: #e4e4e4; color: #666666"')
any_closed = true
end
table.insert(result, '\n|')
if row.line and row.line ~= '' and row.rowspan > 0 then
if (row.rowspan > 1) then
table.insert(result, 'rowspan=' .. row.rowspan)
end
local fill
if mw.ustring.find(row.line, ',') then
local lines = mw.text.split(row.line, ',')
fill = { 'repeating-linear-gradient(135deg' }
local offset = 0
for j, line in ipairs(lines) do
local color = getColor(line)
table.insert(fill, ', ' .. color .. ' ' .. offset .. 'em')
offset = offset + .5
table.insert(fill, ', ' .. color .. ' ' .. offset .. 'em')
end
table.insert(fill, ')')
fill = table.concat(fill)
else
fill = getColor(row.line)
end
table.insert(
result,
' style="width: 0.5em; padding: 0; background: ' .. fill .. '" |\n')
elseif row.line == nil or row.line == '' then
table.insert(result, ' colspan=2 ')
end
table.insert(result, '| ' .. frame:expandTemplate { title = '重庆轨道交通出口标志', args = { row.index } })
if mw.ustring.find(row.tags, 'r') or mw.ustring.find(row.tags, 't') then -- t 兼容中
table.insert(result, ' [[File:CRT Toilet.svg|x24px|卫生间|link=]]')
end
if mw.ustring.find(row.tags, 'A') then
table.insert(result, ' [[File:CRT Accessible.svg|x24px|无障碍坡道|link=]]')
end
if mw.ustring.find(row.tags, 'L') then
table.insert(result, ' [[File:CRT Accessible.svg|x24px|轮椅升降台|link=]]')
end
if mw.ustring.find(row.tags, 'E') or mw.ustring.find(row.tags, 'a') then -- a 兼容中
table.insert(result, ' [[File:CRT Elevator.svg|x24px|无障碍电梯|link=]]')
end
if mw.ustring.find(row.tags, 't') or mw.ustring.find(row.tags, 'a') then -- 追踪兼容参数
unknown_args = true
end
table.insert(result, row.ref .. '\n')
if has_photo then
if row.photo then
table.insert(result, '| [[File:' .. row.photo .. '|140px]]\n')
else
table.insert(result, '|\n')
end
end
table.insert(result, '| ' .. row.loc .. '\n')
if row.targets then
table.insert(result, '| ' .. makeList('horizontal', row.targets) .. '\n')
else
table.insert(result, '| \n')
end
rows[i] = table.concat(result)
end
if any_closed then
table.insert(rows, [[
|- style="font-size: small; text-align: center"
| colspan=]] .. (has_photo and '5' or '4') ..
[[| <span style="background-color: #e4e4e4; color: #666666; outline: #e4e4e4 solid 0.2em">未开通</span>
]])
end
return [[
{| class="wikitable"
|- style="text-align: center; vertical-align: middle"
! style="min-width: 3em" colspan=2 | 出入口
]]
.. (has_photo and '! 照片\n' or '') .. [[
! style="min-width: 4em" | 位置
! style="min-width: 9em" | 目的地
]] .. table.concat(rows) .. '\n|}' .. (unknown_args and '[[Category:在重庆轨道交通出入口使用未知参数的条目]]' or '')
end
p.exit_list = makeInvokeFunction('_exit_list')
return p