Module:Sandbox/ChaoticShadow/InfoboxBuilder: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 20: | Line 20: | ||
bg = 'transparent' |
bg = 'transparent' |
||
}, |
}, |
||
params = { |
params = { |
||
{ name = 'bg color' }, |
|||
{ name = 'text color' } |
|||
}, |
|||
paramnames = { 'bg color', 'text color' }, |
|||
args = {}, |
args = {}, |
||
final_args = {}, |
final_args = {}, |
||
Line 131: | Line 134: | ||
end |
end |
||
local |
local raw_param_value = self.args[param] |
||
local colors = color_table[ |
local colors = color_table[raw_param_value] |
||
if colors == nil then |
if colors == nil then |
||
Line 145: | Line 148: | ||
--- Sets the infobox params |
--- Sets the infobox params |
||
-- @param ... {{ name, func, default }, ...} |
-- @param ... {{ name, func, default, should_hide }, ...} |
||
-- name string |
-- name string |
||
-- The name of the parameter, not nil, cannot be duplicate |
-- The name of the parameter, not nil, cannot be duplicate |
||
Line 163: | Line 166: | ||
end |
end |
||
if self.paramnames[v.name] then |
if self.paramnames[v.name] then |
||
error("name cannot be |
error("name cannot be duplicate") |
||
end |
end |
||
Line 184: | Line 187: | ||
function InfoboxBuilder:setArgs(args) |
function InfoboxBuilder:setArgs(args) |
||
for k,v in pairs(args) do |
for k,v in pairs(args) do |
||
if v ~= '' then |
|||
self.args[k] = v |
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 |
end |
||
Line 200: | Line 212: | ||
end |
end |
||
if self.final_args[param] then |
|||
⚫ | |||
return self.final_args[param] |
|||
end |
|||
⚫ | |||
local current_param = self.params[param] |
|||
if |
if current_param == nil then |
||
error(string.format("No such param: %s", param)) |
error(string.format("No such param: %s", param)) |
||
end |
end |
||
local |
local raw_param_value = self.args[param] or current_param.default |
||
if |
if raw_param_value == nil then |
||
return |
return raw_param_value |
||
end |
end |
||
if |
if current_param['type'] == 'function' then |
||
content = |
content = current_param.func(raw_param_value) |
||
elseif |
elseif current_param['type'] == 'table' then |
||
content = |
content = current_param.func[raw_param_value] |
||
else |
else |
||
content = |
content = raw_param_value |
||
end |
end |
||
Line 301: | Line 317: | ||
local t = {} |
local t = {} |
||
for _,v in ipairs(actual_args) do |
for _,v in ipairs(actual_args) do |
||
table.insert(t, v.title .. |
table.insert(t, v.title .. '=' .. v.content) |
||
end |
end |
||
content = mw.getCurrentFrame():callParserFunction({ |
content = mw.getCurrentFrame():callParserFunction({ |
||
name = '#tag', |
name = '#tag', |
||
args = { 'tabber', table.concat(t, |
args = { 'tabber', table.concat(t, '|-|') } |
||
}) |
}) |
||
end |
end |
||
Line 331: | Line 347: | ||
-- @return self |
-- @return self |
||
-- The current object |
-- The current object |
||
function InfoboxBuilder:addRow(...) |
function InfoboxBuilder:addRow(should_hide, ...) |
||
⚫ | |||
local argt = ... |
local argt = ... |
||
local actual_values = {} |
|||
⚫ | |||
⚫ | |||
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 |
|||
⚫ | |||
for i,v in ipairs(argt) 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 / #argt) |