Jump to content

Module:Sandbox/ChaoticShadow/InfoboxBuilder: Difference between revisions

no edit summary
No edit summary
No edit summary
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
return size
end
 
function InfoboxBuilder.new()
local obj = setmetatable({
Line 32 ⟶ 29:
end
 
--- Set the infobox name, for use with bottom links
-- @param arg string
-- name of the template, not nil or empty
-- @return sizeself
-- the current object
function InfoboxBuilder:setName(arg)
assert(if arg ~== nil) or arg == '' then
error("Template name must not be nil or empty")
end
self.name = arg
Line 39 ⟶ 44:
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)
assert(if arg ~== nil) or arg == '' then
error("Width must not be nil or empty")
end
self.infobox:css('width', arg)
Line 46 ⟶ 60:
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)
assert(if arg ~== nil) or arg == '' then
error("Header text color must not be nil or empty")
end
self.headerColors.text = arg
Line 53 ⟶ 76:
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)
assert(if arg ~== nil) or arg == '' then
error("Header background color must not be nil or empty")
end
self.headerColors.bg = arg
Line 60 ⟶ 92:
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)
assert(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.headerColors.bg = :setHeaderTextColor(arg.bgtext)
self:setHeaderBackgroundColor(arg.bg)
return self
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(...)
for i, v in ipairs(...) do
if v.name and v.name ~= "" then
table.insert(if self.paramnames, [v.name)] == nil then
if type(v.func) == 'function' or type(v.func) == 'table' or type(v.func) == 'string' then
self.params[if type(v.name]func) == 'function' {or
['type'] = type(v.func), == 'table' or
func = type(v.func,) == 'string'
default = v.default then
self.params[v.name] = {
}
['type'] = type(v.func),
table.insert(self.paramnames, v.name)
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
else
error("name must not be nil or empty")
end
end
Line 199 ⟶ 265:
end
 
function InfoboxBuilder:setupColsaddSpacer()
local spacer = self.infobox:tag('tr')
for i=1,30,1 do
439

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.