Module:Sandbox/ChaoticShadow/InfoboxBuilder: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 333: Line 333:


--- Adds a row, with columns up to 30 columns spanned
--- Adds a row, with columns up to 30 columns spanned
-- @param should_hide boolean
-- @param ... { { tag, content, hide, attr, colspan, rowspan, css }, ... }
-- 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"
-- tag "th", "td", "argth", "argtd"
-- A string containing one of the above, "th" or
-- A string containing one of the above, "th" or
Line 347: Line 349:
-- @return self
-- @return self
-- The current object
-- The current object
function InfoboxBuilder:addRow(should_hide, ...)
function InfoboxBuilder:addRow(should_hide, cols)
local argt = ...
local actual_values = {}
local actual_values = {}
for i,v in ipairs(argt) do
for i,v in ipairs(cols) do
if v.tag == 'argth' or v.tag == 'argtd' then
if v.tag == 'argth' or v.tag == 'argtd' then
table.insert(actual_values, self:getContent(v.content))
table.insert(actual_values, self:getContent(v.content))
Line 358: Line 358:
end
end
if should_hide and #actual_values == 0 then
return mw.dumpObject(argt)
return self
-- if should_hide and #actual_values > 0 then
end
-- return self
-- end
-- local _row = self.infobox:tag('tr')
local _row = self.infobox:tag('tr')
-- for i,v in ipairs(argt) do
for i,v in ipairs(cols) do
-- local _cell = _row:tag(tagmap[v.tag] or 'td')
local _cell = _row:tag(tagmap[v.tag] or 'td')
-- :attr('colspan', 30 / #argt)
:attr('colspan', 30 / #cols)
-- if v.attr then
if v.attr then
-- _cell:attr(v.attr)
_cell:attr(v.attr)
-- end
end
-- if v.colspan then
if v.colspan then
-- _cell:attr('colspan', v.colspan)
_cell:attr('colspan', v.colspan)
-- end
end
-- if v.rowspan then
if v.rowspan then
-- _cell:attr('rowspan', v.rowspan)
_cell:attr('rowspan', v.rowspan)
-- end
end
-- if v.css then
if v.css then
-- _cell:css(v.css)
_cell:css(v.css)
-- end
end
-- if v.tag == 'th' or v.tag == 'td' then
if v.tag == 'th' or v.tag == 'td' then
-- _cell:wikitext(v.content)
_cell:wikitext(v.content)
-- elseif v.tag == 'argth' or v.tag == 'argtd' then
elseif v.tag == 'argth' or v.tag == 'argtd' then
-- _cell:wikitext(self:getContent(v.content))
_cell:wikitext(self:getContent(v.content))
-- end
end
-- end
end
-- return self
return self
end
end