Module:Sandbox/ChaoticShadow/InfoboxBuilder: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 10: | Line 10: | ||
} |
} |
||
--- Create the infobox |
|||
local function tableSize(tbl) |
|||
-- @return obj metatable |
|||
local size = 0 |
|||
-- a metatable describing the infobox |
|||
for i, v in ipairs(tbl) do size = size + 1 end |
|||
⚫ | |||
⚫ | |||
function InfoboxBuilder.new() |
function InfoboxBuilder.new() |
||
local obj = setmetatable({ |
local obj = setmetatable({ |
||
Line 32: | Line 29: | ||
end |
end |
||
--- Set the infobox name, for use with bottom links |
|||
-- @param arg string |
|||
-- name of the template, not nil or empty |
|||
⚫ | |||
-- the current object |
|||
function InfoboxBuilder:setName(arg) |
function InfoboxBuilder:setName(arg) |
||
if arg == nil or arg == '' then |
|||
error("Template name must not be nil or empty") |
|||
⚫ | |||
self.name = arg |
self.name = arg |
||
Line 39: | Line 44: | ||
end |
end |
||
--- Set the width of the infobox |
|||
-- @param arg string |
|||
-- width of the infobox, should be a valid value for the CSS "width" |
|||
-- property, not nil or empty |
|||
-- @return self |
|||
-- the current object |
|||
function InfoboxBuilder:setWidth(arg) |
function InfoboxBuilder:setWidth(arg) |
||
if arg == nil or arg == '' then |
|||
error("Width must not be nil or empty") |
|||
end |
|||
self.infobox:css('width', arg) |
self.infobox:css('width', arg) |
||
Line 46: | Line 60: | ||
end |
end |
||
--- Set the text color of the header |
|||
-- @param arg string |
|||
-- text color of the header, should be a valid value for the CSS |
|||
-- "color" property, not nil or empty |
|||
-- @return self |
|||
-- the current object |
|||
function InfoboxBuilder:setHeaderTextColor(arg) |
function InfoboxBuilder:setHeaderTextColor(arg) |
||
if arg == nil or arg == '' then |
|||
error("Header text color must not be nil or empty") |
|||
end |
|||
self.headerColors.text = arg |
self.headerColors.text = arg |
||
Line 53: | Line 76: | ||
end |
end |
||
--- Set the background color of the header |
|||
-- @param arg string |
|||
-- background color of the header, should be a valid value for the |
|||
-- CSS "background-color" property, not nil or empty |
|||
-- @return self |
|||
-- the current object |
|||
function InfoboxBuilder:setHeaderBackgroundColor(arg) |
function InfoboxBuilder:setHeaderBackgroundColor(arg) |
||
if arg == nil or arg == '' then |
|||
error("Header background color must not be nil or empty") |
|||
end |
|||
self.headerColors.bg = arg |
self.headerColors.bg = arg |
||
Line 60: | Line 92: | ||
end |
end |
||
--- Sets both the text and background color of the header |
|||
-- @param arg { text, bg } |
|||
-- text string |
|||
-- Same as setHeaderTextColor |
|||
-- bg string |
|||
-- Same as setHeaderBackgroundColor |
|||
-- @return self |
|||
-- the current object |
|||
function InfoboxBuilder:setHeaderColors(arg) |
function InfoboxBuilder:setHeaderColors(arg) |
||
if arg == nil then |
|||
error("Header colors must not be nil") |
|||
assert(arg.text ~= nil) |
|||
end |
|||
assert(arg.bg ~= nil) |
|||
self.headerColors.text = arg.text |
|||
self |
self:setHeaderTextColor(arg.text) |
||
self:setHeaderBackgroundColor(arg.bg) |
|||
return self |
return self |
||
end |
end |
||
--- Sets the infobox params |
|||
-- @params ... {{ name, func, default }, ...} |
|||
-- name string |
|||
-- The name of the parameter, not nil cannot be duplicate |
|||
-- func function, table or string |
|||
-- A function that accepts the parameter as an argument and |
|||
-- returns a string, OR |
|||
-- A table that has the parameter as a key, OR |
|||
-- An empty string |
|||
-- default string or nil |
|||
-- The default value if no argument is given |
|||
-- @return self |
|||
-- the current object |
|||
function InfoboxBuilder:setParams(...) |
function InfoboxBuilder:setParams(...) |
||
for i, v in ipairs(...) do |
for i, v in ipairs(...) do |
||
if v.name then |
if v.name and v.name ~= "" then |
||
⚫ | |||
if type(v.func) == 'function' or type(v.func) == 'table' or type(v.func) == 'string' then |
|||
if type(v.func) == 'function' or |
|||
type(v.func) == 'table' or |
|||
type(v.func) == 'string' |
|||
then |
|||
self.params[v.name] = { |
|||
⚫ | |||
['type'] = type(v.func), |
|||
⚫ | |||
func = v.func, |
|||
default = v.default |
|||
⚫ | |||
table.insert(self.paramnames, v.name) |
|||
else |
|||
error("func must be of type \"function\", \"table\", or " .. |
|||
"\"string\"") |
|||
end |
|||
else |
|||
error("name cannot be duplicaate") |
|||
end |
end |
||
else |
|||
error("name must not be nil or empty") |
|||
end |
end |
||
end |
end |
||
Line 199: | Line 265: | ||
end |
end |
||
function InfoboxBuilder: |
function InfoboxBuilder:addSpacer() |
||
local spacer = self.infobox:tag('tr') |
local spacer = self.infobox:tag('tr') |
||
for i=1,30,1 do |
for i=1,30,1 do |