Documentation for this module may be created at Module:Deck Layout/doc
local p = {}
function p.render(frame)
local layout = frame.args.layout or ""
local name = frame.args.name or ""
local rows = mw.text.split(layout, "\n")
local output = {}
local rowCount = #rows
local colCount = 0
for _, row in ipairs(rows) do
colCount = math.max(colCount, mw.ustring.len(row))
end
-- Table start
table.insert(output, '{| class="deck-layout"')
-- Caption with class "deck-title"
if name ~= "" then
table.insert(output, '|+ class="deck-title" | ' .. name)
end
-- Top row
table.insert(output, "|-")
for c = 0, colCount + 1 do
local cls = "border-top"
if c == 0 then cls = "corner-tl"
elseif c == colCount + 1 then cls = "corner-tr" end
table.insert(output, string.format('| class="%s" |', cls))
end
-- Middle rows
for r = 1, rowCount do
local row = rows[r]
table.insert(output, "|-")
-- Left border
table.insert(output, '| class="border-left" |')
for c = 1, colCount do
local cell = row:sub(c, c)
local class = "center"
if cell == "O" then
class = "slot-free"
elseif cell == "X" then
class = "slot-disabled"
end
table.insert(output, string.format('| class="%s" |', class))
end
-- Right border
table.insert(output, '| class="border-right" |')
end
-- Bottom row
table.insert(output, "|-")
for c = 0, colCount + 1 do
local cls = "border-bottom"
if c == 0 then cls = "corner-bl"
elseif c == colCount + 1 then cls = "corner-br" end
table.insert(output, string.format('| class="%s" |', cls))
end
-- Table end
table.insert(output, "|}")
return table.concat(output, "\n")
end
return p