Module:Sandbox/ChaoticShadow/InfoboxBuilder: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 117: | Line 117: | ||
--- Sets both the text and background color of the header |
--- Sets both the text and background color of the header |
||
-- @param |
-- @param param_name string |
||
-- Parameter name that helps map the colors |
-- Parameter name that helps map the colors |
||
-- @param color_table { text, bg } |
-- @param color_table { text, bg } |
||
-- text string |
-- text string |
||
Line 126: | Line 126: | ||
-- @return self |
-- @return self |
||
-- The current object |
-- The current object |
||
function InfoboxBuilder:setHeaderColorsByParam( |
function InfoboxBuilder:setHeaderColorsByParam(param_name, color_table) |
||
if |
if param_name == nil then |
||
error("Parameter name must not be nil") |
error("Parameter name must not be nil") |
||
elseif color_table == nil then |
elseif color_table == nil then |
||
Line 133: | Line 133: | ||
end |
end |
||
local raw_param_value = self.raw_args[ |
local raw_param_value = self.raw_args[param_name] |
||
local colors = color_table[raw_param_value] |
local colors = color_table[raw_param_value] |
||
Line 202: | Line 202: | ||
--- Gets the content associated with a parameter |
--- Gets the content associated with a parameter |
||
-- @param |
-- @param param_name string |
||
-- The param name, not nil or empty |
-- The param name, not nil or empty |
||
-- @return content string |
-- @return content string |
||
-- A string containing the content |
-- A string containing the content |
||
function InfoboxBuilder:getContent( |
function InfoboxBuilder:getContent(param_name) |
||
if |
if param_name == nil or param_name == "" then |
||
error("Param must not be nil or empty") |
error("Param must not be nil or empty") |
||
end |
end |
||
if self.proc_args[ |
if self.proc_args[param_name] then |
||
return self.proc_args[ |
return self.proc_args[param_name] |
||
end |
end |
||
local content = nil |
local content = nil |
||
local current_param = self.params[ |
local current_param = self.params[param_name] |
||
if current_param == nil then |
if current_param == nil then |
||
error(string.format("No such param: %s", |
error(string.format("No such param with name: %s", param_name)) |
||
end |
end |
||
local raw_param_value = self.raw_args[ |
local raw_param_value = self.raw_args[param_name] or current_param.default |
||
if raw_param_value == nil then |
if raw_param_value == nil then |
||
Line 239: | Line 239: | ||
return content |
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 = {} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
return actual_values |
|||
end |
end |
||
--- Adds a header |
--- Adds a header |
||
-- @param arg { content, attr, colspan, rowspan, css } |
-- @param arg { content, attr, colspan, rowspan, css } |
||
-- content string or nil |
-- content string or nil |
||
-- |
-- The wikitext to be rendered |
||
-- |
-- attr {...} or nil |
||
-- |
-- The attributes of the cell in table form |
||
-- |
-- colspan number or nil |
||
-- 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 |
-- @return self |
||
-- The current object |
-- The current object |
||
Line 286: | Line 307: | ||
--- Adds an image, or switchable images |
--- Adds an image, or switchable images |
||
-- @param ... { { tag, content, title }, ... } |
-- @param ... { { tag, content, title }, ... } |
||
-- tag "artd" or "td" |
-- tag "artd" or "td" |
||
-- |
-- Whether or not an it is based off a parameter |
||
-- |
-- content string |
||
-- The content or the parameter name |
|||
-- title string or nil |
|||
-- The title, if using switchable images |
|||
-- @return self |
-- @return self |
||
-- The current object |
-- The current object |
||
Line 332: | Line 356: | ||
--- Adds a row, with columns up to 30 columns spanned |
--- 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 }, ... } |
-- @param cols { { tag, content, hide, attr, colspan, rowspan, css }, ... } |
||
-- tag "th", "td", "argth", "argtd" |
-- tag "th", "td", "argth", "argtd" |
||
-- |
-- A string containing one of the above, "th" or "td" uses |
||
-- |
-- content as the wikitext, "argth" or "argtd" uses content as |
||
-- |
-- the parameter name to produce the suitable content |
||
-- content string |
|||
-- to produce the suitable content |
|||
-- |
-- Content to be used as wikitext or a parameter name |
||
-- |
-- attr {...} or nil |
||
-- |
-- The attributes of the cell in table form |
||
-- colspan number or nil |
-- colspan number or nil |
||
-- |
-- The colspan of the cell |
||
-- |
-- rowspan number or nil |
||
-- 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 |
-- @return self |
||
-- The current object |
-- The current object |
||
function InfoboxBuilder:addRow( |
function InfoboxBuilder:addRow(cols, options) |
||
if options then |
if options then |
||
if options.hideIfEmpty and #options.hideIfEmpty > 0 then |
if options.hideIfEmpty and #options.hideIfEmpty > 0 then |
||
local actual_values = |
local actual_values = self:getNonNilContent(options.hideIfEmpty) |
||
⚫ | |||
⚫ | |||
⚫ | |||
if #actual_values == 0 then |
if #actual_values == 0 then |