Jump to content

Module:Rb row/common

From Wiki - Scioly.org
Revision as of 17:45, 18 December 2024 by Nydauron (talk | contribs) (Removes variable definition in favor of argument)

Documentation for this module may be created at Module:Rb row/common/doc

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 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 reasonmessage
function p.generateConditionRow(conditionType, columnCount, 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
		text = "Cancelled"
	elseif conditionType == eventNotHeldValue then
		isValidCondition = true
		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