Module:Sandbox/BrandonXLF/1: Difference between revisions

Content deleted Content added
No edit summary
Restored revision 1241724286 by BrandonXLF (Restorer)
 
(36 intermediate revisions by the same user not shown)
Line 5:
local p = {}
 
-- Parameters that can be numbered
local function displayService(service, dest, dir)
local numeredParams = {
service = true,
dest = true,
note = true
}
 
-- Labels for platform types
local platformLabels = {
island = 'Island platform',
top = 'Side platform',
bottom = 'Side platform'
}
 
-- Generate the HTML to display a service
local function displayService(service, dest, note, dir)
if not service then return '' end
return '<div>' .. (dir class== 'left' and '←' or '→') .. ' ' .. "service .. ' toward ">' .. dest .. '</div>'
'<div class="' .. (dir ~= 'left' and 'hidden' or '') .. '">←</div>' ..
'<div>' .. service .. (dest and ' toward ' .. dest or '') .. (note and ' ' .. note or '') .. '</div>' ..
(dir == 'right' and '<div>→</div>' or '') ..
'</div>'
end
 
-- Generate the HTML to display a track (one or more services)
local function displayTrack(floorPart)
localif outnot = displayService(floorPart.service, floorPart.dest, floorPart.dir)then
return ''
end
floorPart.dest = floorPart.dest or {}
floorPart.note = floorPart.note or {}
local out = ''
for i = 1, floorPart.service.max do
out = out .. displayService(floorPart.service[i].service, floorPart.dest[i], floorPart.destnote[i], floorPart.dir)
end
Line 21 ⟶ 48:
end
 
-- Generate the HTML to generate a "row" of the floor
local function displayFloorPart(floorPart, floorNum, partNum)
local out = ''
local out = '<div style="display: grid; grid-template-columns: max-content 1fr;">'
if floorPart.name then
out = out ..return '<div class="track"><div>' .. floorPart.name .. '</div></div>' ..
out '<div class="track"><div outclass="desc"><div>' .. (floorPart.desc or '') .. '</div>' .. displayTrack(floorPart) .. '</div></div>'
elseif floorPart.platform then
out = out .. '<div style="grid-column: 1 / 3;">' .. floorPart.platform .. '</div>'
else
local prefix = floorNum .. '_' .. partNum .. '_'
out = out .. 'Invalid floor part! Must have either <code>' .. prefix .. 'name</code> or <code>' .. prefix .. 'platform</code>.'
end
elseifif floorPart.platform then
return out .. '</div>'
if not platformLabels[floorPart.platform] then
end
return '<div class="part-error">Invalid platform type!</div>'
end
out = out ..return '<div styleclass="grid-column:platform 1 / 3;">' .. floorPart.platform .. '</div">' ..
platformLabels[floorPart.platform] ..
(floorPart.accessible and ' ' .. mw.getCurrentFrame():expandTemplate{ title = 'access icon' } or '') ..
(floorPart.note and ', ' .. floorPart.note or '') ..
'</div>'
end
 
local prefix = floorNum .. '_' .. partNum .. '_'
local function displayFloor(stationFloor, num)
local out = '<div>' .. stationFloor.letter .. '</div>'
out return '<div class= out .. '"part-error">Invalid floor part! Must have either <code>' .. prefix .. 'name</code> or <code>' .. prefix .. 'platform</code></div>.'
out = out .. '<div>'
end
 
-- Generate the HTML to display a floor
local function displayFloor(stationFloor, num, last)
local out = '<div class="floor' .. (last and ' last' or '') .. '" style="grid-row: span ' .. stationFloor.count .. ';">' .. stationFloor.letter .. '</div>'
 
for i = 1, stationFloor.max do
Line 47 ⟶ 82:
end
return out .. '</div>'
end
 
-- Create a table that can hold numbered arguments
local function addArgcreateArgTable(tbl, num)
tbl = tbl or {}
tbl.max = 0
tbl.count = 0
return tbl
end
 
-- Add an argument number to a table of numbered arguments
local function addArg(tbl, num)
local function addArg(tbl, num, value)
if num > tbl.max then
tbl.max = num
Line 56 ⟶ 102:
if not tbl[num] then
tbl[num] = { max = 0 }value
tbl.count = tbl.count + 1
end
end
-- Process an argument with the format level_part_param[paramNum]
local function processArg(out, level, part, serviceparam, paramparamNum, value)
level = tonumber(level)
part = tonumber(part)
serviceparamNum = serviceparamNum and tonumber(serviceparamNum) or nil1
addArg(out, level, createArgTable())
addArg(out[level], part, {})
if servicenumeredParams[param] then
addArg(if not out[level][part],[param] service)then
out[level][part][service][param] = valuecreateArgTable()
end
addArg(out[level][part][param], paramNum, value)
else
out[level][part][param] = value
Line 76 ⟶ 127:
end
-- Process the argument table
local function processArgs(args)
local out = { max = 0 }createArgTable()
for i, v in pairs(args) do
if type(i) == 'number' then
addArg(out, i, createArgTable({ letter = v }))
local level = tonumber(i)
if not out[level] then
out[level] = { max = 0 }
end
out[level].letter = v
else
local level, part, serviceparam, paramparamNum = i:match('(%d+)_(%d+)_?([^%d*]+)_(.+%d*)')
if level and part and param then
processArg(out, level, part, serviceparam, paramparamNum, v)
end
end
Line 100 ⟶ 146:
end
 
-- Main function, called by wikitext
 
function p.main(frame)
local sortedArgs = processArgs(frame.args)
local out = frame:extensionTag{
local out = '<div style="display: grid; grid-template-columns: max-content 1fr;">'
name = 'templatestyles',
args = { src = 'User:BrandonXLF/styles.css' }
}
out = out .. '<div class="station-layout">'
for i = 1, sortedArgs.max do
out = out .. displayFloor(sortedArgs[i], i, i == sortedArgs.max)
end