Module:Rb row/common
Appearance
Documentation for this module may be created at Module:Rb row/common/doc
-- This module is used in both "Irb row" and "Rrb row" modules. If a non-backwards
-- compatible change is made to this file, please ensure both modules are tested
-- and updated accordingly.
local p = {}
---@param conditionType string the type of condition. Should match one either eventCancelledValue or eventNotHeldValue.
---@param columnCount number The number of columns that the row will span
---@param enableColumnColor boolean Whether the background color of the cell should be shown. Varies based on the type of condition (conditionType).
---@param eventCancelledValue string The string literal that represents that the event was cancelled
---@param eventNotHeldValue string The string literal that represents that the event was not held
---@param conditionReason string? Specifies the reason as to why the condition happened
---@param conditionMessageOverride string? Overrides the default condition template with a custom reason message
---@return mw.html # The table cell ("td")
function p.generateConditionRow(conditionType, columnCount, enableColumnColor, eventCancelledValue, eventNotHeldValue, conditionReason, conditionMessageOverride)
local conditionCell = mw.html.create("td")
conditionCell:attr("colspan", tostring(columnCount))
local isValidCondition = false
local text = ""
if conditionType == eventCancelledValue then
isValidCondition = true
if enableColumnColor then
conditionCell:css({["background"] = "#ffdddd"})
end
text = "Cancelled"
elseif conditionType == eventNotHeldValue then
isValidCondition = true
if enableColumnColor then
conditionCell:css({["background"] = "#ffdead"})
end
text = "Not held"
end
if isValidCondition then
if conditionMessageOverride ~= nil then
text = string.format("''%s %s''", text, conditionMessageOverride)
elseif conditionReason ~= nil then
text = string.format("''%s due to %s''", text, conditionReason)
else
text = string.format("''%s''", text)
end
else
mw.addWarning(string.format("Condition can only be %s or %s", eventCancelledValue, eventNotHeldValue))
end
conditionCell:wikitext(text)
return conditionCell
end
return p