Jump to content

Module:Sandbox/ChaoticShadow/InfoboxBuilder: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 117:
 
--- Sets both the text and background color of the header
-- @param paramparam_name string
-- Parameter name that helps map the colors
-- @param color_table { text, bg }
-- text string
Line 126:
-- @return self
-- The current object
function InfoboxBuilder:setHeaderColorsByParam(paramparam_name, color_table)
if paramparam_name == nil then
error("Parameter name must not be nil")
elseif color_table == nil then
Line 133:
end
local raw_param_value = self.raw_args[paramparam_name]
local colors = color_table[raw_param_value]
Line 202:
 
--- Gets the content associated with a parameter
-- @param paramparam_name string
-- The param name, not nil or empty
-- @return content string
-- A string containing the content
function InfoboxBuilder:getContent(paramparam_name)
if paramparam_name == nil or paramparam_name == "" then
error("Param must not be nil or empty")
end
if self.proc_args[paramparam_name] then
return self.proc_args[paramparam_name]
end
local content = nil
local current_param = self.params[paramparam_name]
if current_param == nil then
error(string.format("No such param with name: %s", paramparam_name))
end
local raw_param_value = self.raw_args[paramparam_name] or current_param.default
if raw_param_value == nil then
Line 239:
return content
end
 
--- Gets the non-nil content from a list of param names
-- @param param_names { param_name, ... }
-- param_name string
-- The param name
-- @return actual_values { content, ... }
-- content string
-- The processed content associated with a param
function InfoboxBuilder:getNonNilContent(param_names)
local actual_values = {}
for i,v in ipairs(options.hideIfEmptyparam_names) do
table.insert(actual_values, self:getContent(v))
end
return actual_values
end
 
--- Adds a header
-- @param arg { content, attr, colspan, rowspan, css }
-- content string or nil The wikitext to be rendered
-- attr {...} or nil The attributeswikitext ofto thebe cell in table formrendered
-- colspanattr number or nil The{...} colspanor of thenil cell
-- roswpan number or nil The rowspanattributes of the cell in table form
-- csscolspan {...}number or nil The css of the cell in table form
-- The colspan of the cell
-- roswpan number or nil
-- The rowspan of the cell
-- css {...} or nil
-- The css of the cell in table form
-- @return self
-- The current object
Line 286 ⟶ 307:
--- Adds an image, or switchable images
-- @param ... { { tag, content, title }, ... }
-- tag "artd" or "td" Whether or not an it is based off a parameter
-- content string Whether or Thenot contentan orit theis parameterbased nameoff a parameter
-- title content string or nil The title, if using switchable images
-- The content or the parameter name
-- title string or nil
-- The title, if using switchable images
-- @return self
-- The current object
Line 332 ⟶ 356:
 
--- Adds a row, with columns up to 30 columns spanned
-- @param should_hide boolean
-- The row will be hidden if all varying columns are nil
-- @param cols { { tag, content, hide, attr, colspan, rowspan, css }, ... }
-- tag "th", "td", "argth", "argtd"
-- A string containing one of the above, "th" or "td" uses
-- content as the wikitext, "argth" or "tdargtd" uses content as the wikitext, "argth" or
-- the parameter name to produce the "argtd" usessuitable content as the parameter name
-- content string
-- to produce the suitable content
-- content string Content to be used as wikitext or a parameter name
-- attr {...} or namenil
-- attr {...} or nil The attributes of the cell in table form
-- colspan number or nil The colspan of the cell
-- rowspan number or nil The rowspancolspan of the cell
-- cssrowspan {...}number or nil The css of the cell in table form
-- The rowspan of the cell
-- css {...} or nil
-- The css of the cell in table form
-- @param options { hideIfEmpty }
-- hideIfEmpty { param_name, ... }
-- param_name string
-- The param_name that will be used to check if corresponding
-- content is nil
-- @return self
-- The current object
function InfoboxBuilder:addRow(should_hide, cols, options)
if options then
if options.hideIfEmpty and #options.hideIfEmpty > 0 then
local actual_values = {}self:getNonNilContent(options.hideIfEmpty)
for i,v in ipairs(options.hideIfEmpty) do
table.insert(actual_values, self:getContent(v))
end
if #actual_values == 0 then
439

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.