Module:Sandbox/ChaoticShadow/InfoboxBuilder: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 241: Line 241:
end
end


--- Gets the non-nil content from a list of param names
--- Determines if the row should be shown based of a list of param names
-- @param param_names { param_name, ... }
-- @param param_names { param_name, ... }
-- param_name string
-- param_name string
-- The param name
-- The param name
-- @return actual_values { content, ... }
-- @return should_show boolean
function InfoboxBuilder:shouldShow(param_names)
-- content string
if param_names and #param_names > 0 then
-- The processed content associated with a param
local actual_values = {}
function InfoboxBuilder:getNonNilContent(param_names)
for i,v in ipairs(param_names) do
local actual_values = {}
table.insert(actual_values, self:getContent(v))
for i,v in ipairs(param_names) do
end
table.insert(actual_values, self:getContent(v))
if #actual_values == 0 then
return false
end
end
end
return actual_values
return true
end
end



--- Adds a header
--- Adds a header
Line 269: Line 274:
-- css {...} or nil
-- css {...} or nil
-- The css of the cell in table form
-- 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:addHeader(arg)
function InfoboxBuilder:addHeader(arg, options)
if options then
if not self:shouldShow(options.hideIfEmpty) then
return self
end
end
self:addSpacer()
self:addSpacer()
Line 306: Line 322:


--- Adds an image, or switchable images
--- Adds an image, or switchable images
-- @param ... { { tag, content, title }, ... }
-- @param cols { { tag, content, title }, ... }
-- tag "artd" or "td"
-- tag "artd" or "td"
-- Whether or not an it is based off a parameter
-- Whether or not an it is based off a parameter
Line 313: Line 329:
-- title string or nil
-- title string or nil
-- The title, if using switchable images
-- The title, if using switchable images
-- @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:addImage(...)
function InfoboxBuilder:addImage(cols, options)
if options then
local argt = ...
if not self:shouldShow(options.hideIfEmpty) then
return self
end
end
local _cell = self.infobox:tag('tr'):tag('td'):css('text-align', 'center')
local _cell = self.infobox:tag('tr'):tag('td'):css('text-align', 'center')
Line 322: Line 347:
local actual_args = {}
local actual_args = {}
for _,v in ipairs(argt) do
for _,v in ipairs(cols) do
local c = v.content
local c = v.content
if v.tag == 'argtd' then
if v.tag == 'argtd' then
Line 380: Line 405:
function InfoboxBuilder:addRow(cols, options)
function InfoboxBuilder:addRow(cols, options)
if options then
if options then
if options.hideIfEmpty and #options.hideIfEmpty > 0 then
if not self:shouldShow(options.hideIfEmpty) then
return self
local actual_values = self:getNonNilContent(options.hideIfEmpty)
end
if #actual_values == 0 then
return self
end
end
end
end