Module:Row
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Row/doc
-- Module definition
local p = {}
-- Function to generate the row
function p.Row(frame)
local args = frame:getParent().args
local numColumns = (args.columns or 5) -- Maximum number of columns
-- Table attributes
local class =
"jjbe-row volume" .. (args.diamond == "true" and " diamond" or "") .. (args.class and (" " .. args.class) or "")
local style = "display: table; width: " .. (args.width or "100%") .. "; height: " .. (args.height or "100%") .. ";"
style = style .. "font-size: " .. (args.font or "13px") .. ";"
style =
style .. (args.align == "center" and "margin: auto;" or "") .. (args.align == "right" and "float: right;" or "")
style = style .. "background-color: " .. (args.bg or "white") .. ";"
style = style .. "text-align: " .. (args.textAlign or "center") .. ";"
if args.color then
style = style .. "color: " .. args.color .. ";"
end
-- Add id if provided
local id = args.id and (' id="' .. args.id .. '"') or ""
local result = '<div class="' .. class .. '"' .. id .. ' style="' .. style .. '">'
local columnCount = 0
for i = 1, numColumns do
if args[i] and args[i] ~= "" then
columnCount = columnCount + 1
end
end
-- Generate columns
for i = 1, numColumns do
if args[i] and args[i] ~= "" then -- Check if column content exists
local columnClass = "rowTemplate" .. (i == 1 and args.image == "true" and " rowheadimg" or "")
columnClass = columnClass .. (args["class" .. i] and (" " .. args["class" .. i]) or "")
local customClass = args["c" .. i] and (" " .. args["c" .. i]) or ""
-- Determine the width for this column
local width = args["w" .. i] -- Specific width for this column if provided
if not width then
-- If specific width is not provided, calculate default based on the number of columns
if columnCount == 3 then
width = "33.33%"
else
width = (100 / columnCount) .. "%"
end
end
local columnStyle = "display: table-cell; padding: 3px;"
if width then
columnStyle = columnStyle .. "width: " .. width .. ";"
end
columnStyle = columnStyle .. "text-align: " .. (args["textAlign" .. i] or args.textAlign or "center") .. ";"
columnStyle = columnStyle .. "background-color: " .. (args["bg" .. i] or args.bg or "transparent") .. ";"
if (args["color" .. i] or args.color) then
columnStyle = columnStyle .. "color: " .. (args["color" .. i] or args.color or "initial") .. ";"
end
columnStyle = columnStyle .. "border: " .. (args.borderSize or "1px") .. " solid " .. (args.border or "#aaaaaa") .. ";"
columnStyle = columnStyle .. "vertical-align: middle;"
result =
result ..
'<div class="' ..
columnClass .. (args.diamond == "true" and " diamond" or "") ..
'" style="' ..
columnStyle ..
'">' .. '<div class="' .. customClass .. ' rowColumn">' .. args[i] .. "</div></div>"
end
end
result = result .. "</div>"
return result
end
return p