Module:Sandbox/ChaoticShadow/InfoboxBuilder: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 20:
bg = 'transparent'
},
params = {},
paramnames { name = {'bg color' },
{ name = 'text color' }
},
paramnames = { 'bg color', 'text color' },
args = {},
final_args = {},
Line 131 ⟶ 134:
end
local param_contentraw_param_value = self:getContent(.args[param)]
local colors = color_table[param_contentraw_param_value]
if colors == nil then
Line 145 ⟶ 148:
 
--- Sets the infobox params
-- @param ... {{ name, func, default, should_hide }, ...}
-- name string
-- The name of the parameter, not nil, cannot be duplicate
Line 163 ⟶ 166:
end
if self.paramnames[v.name] then
error("name cannot be duplicaateduplicate")
end
Line 184 ⟶ 187:
function InfoboxBuilder:setArgs(args)
for k,v in pairs(args) do
if v ~= '' then
self.args[k] = v
end
end
if self.args['bg color'] then
self:setHeaderBackgroundColor(self.args['bg color'])
end
if self.args['text color'] then
self:setHeaderTextColor(self.args['text color'])
end
Line 200 ⟶ 212:
end
if self.final_args[param] then
local content = '?'
local argparams = return self.paramsfinal_args[param]
end
local content = '?'nil
local current_param = self.params[param]
if argparamscurrent_param == nil then
error(string.format("No such param: %s", param))
end
local argraw_param_value = self.args[param] or self.params[param]current_param.default
if argraw_param_value == nil then
return argraw_param_value
end
if argparamscurrent_param['type'] == 'function' then
content = self.params[param]current_param.func(argraw_param_value)
elseif argparamscurrent_param['type'] == 'table' then
content = self.params[param]current_param.func[argraw_param_value]
else
content = argraw_param_value
end
Line 301 ⟶ 317:
local t = {}
for _,v in ipairs(actual_args) do
table.insert(t, v.title .. "'="' .. v.content)
end
content = mw.getCurrentFrame():callParserFunction({
name = '#tag',
args = { 'tabber', table.concat(t, "'|-|"') }
})
end
Line 331 ⟶ 347:
-- @return self
-- The current object
function InfoboxBuilder:addRow(should_hide, ...)
local _row = self.infobox:tag('tr')
local argt = ...
local actual_values = {}
for i, v in ipairs(argt) do
for i, v in ipairs(argt) do
if v.tag == 'argth' or v.tag == 'argtd' then
table.insert(actual_values, self:getContent(v.content))
end
end
-- if should_hide and #actual_values > 0 then
-- return self
-- end
local _row = self.infobox:tag('tr')
for i,v in ipairs(argt) do
local _cell = _row:tag(tagmap[v.tag] or 'td')
:attr('colspan', 30 / #argt)
439

edits