Module:Row

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 09:44, 27 February 2024 by Vish (talk | contribs) (Created page with "-- Module definition local p = {} -- Function to generate the row function p.Row(frame) local args = frame:getParent().args local numColumns = 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%") .. ";" styl...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 = 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 .. "border: " .. (args.borderSize or "1px") .. " solid " .. (args.border or "#2d519c5c") .. ";"
    style = style .. "background-color: " .. (args.bg or "white") .. ";"
    style = style .. "text-align: " .. (args.textAlign or "center") .. ";"

    local result = '<div class="' .. class .. '" 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 "")
            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 == 1 then
                    width = "100%"
                elseif columnCount == 2 then
                    if i == 1 then
                        width = "22%" -- Set the first column's width to 22%
                    else
                        width = "78%" -- Set the second column's width to 78%
                    end
                elseif columnCount == 3 then
                    width = "33.33%"
                elseif columnCount == 4 then
                    width = "25%"
                elseif columnCount == 5 then
                    width = "20%"
                end
            end
            local columnStyle = "display: table-cell; padding: 6px;"
            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") .. ";"
            columnStyle = columnStyle .. "vertical-align: middle;"
            -- Apply border styles conditionally
            if i == columnCount then
                -- Last column, remove right border
                columnStyle = columnStyle .. "border-right: none;"
            else
                -- Not the last column, standard border
                columnStyle =
                    columnStyle ..
                    "border-right: " .. (args.borderSize or "1px") .. " solid " .. (args.border or "#2d519c5c") .. ";"
            end
            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