Module:Sandbox/ChaoticShadow/InfoboxBuilder: Difference between revisions
no edit summary
No edit summary |
No edit summary |
||
Line 10:
}
--- Create the infobox
-- @return obj metatable
-- a metatable describing the infobox
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
-- the current object
function InfoboxBuilder:setName(arg)
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)
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)
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)
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)
error("Header colors must not be nil")
end
self
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
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:
local spacer = self.infobox:tag('tr')
for i=1,30,1 do
|