More actions
Created page with "local p = {} function p.render(frame) local layout = frame.args.layout 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 -- Top row table.insert(output, "|-") for c = 0, colCount + 1 do local cls = "border-top" if c == 0 then cls = "corner-tl" elseif c == co..." |
rewrite to use mediawiki caption |
||
Line 3: | Line 3: | ||
function p.render(frame) | function p.render(frame) | ||
local layout = frame.args.layout or "" | local layout = frame.args.layout or "" | ||
local name = frame.args.name or "" | |||
local rows = mw.text.split(layout, "\n") | local rows = mw.text.split(layout, "\n") | ||
local output = {} | local output = {} | ||
Line 10: | Line 11: | ||
for _, row in ipairs(rows) do | for _, row in ipairs(rows) do | ||
colCount = math.max(colCount, mw.ustring.len(row)) | 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 | end | ||
Line 52: | Line 61: | ||
table.insert(output, string.format('| class="%s" |', cls)) | table.insert(output, string.format('| class="%s" |', cls)) | ||
end | end | ||
-- Table end | |||
table.insert(output, "|}") | |||
return table.concat(output, "\n") | return table.concat(output, "\n") |
Latest revision as of 23:00, 11 July 2025
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