Module:Sandbox/ChaoticShadow/InfoboxBuilder: Difference between revisions
no edit summary
No edit summary |
No edit summary |
||
Line 12:
--- Create the infobox
-- @return obj metatable
--
function InfoboxBuilder.new()
local obj = setmetatable({
Line 31:
--- Set the infobox name, for use with bottom links
-- @param arg string
--
-- @return self
--
function InfoboxBuilder:setName(arg)
if arg == nil or arg == '' then
Line 46:
--- Set the width of the infobox
-- @param arg string
--
-- property, not nil or empty
-- @return self
--
function InfoboxBuilder:setWidth(arg)
if arg == nil or arg == '' then
Line 62:
--- Set the text color of the header
-- @param arg string
--
-- "color" property, not nil or empty
-- @return self
--
function InfoboxBuilder:setHeaderTextColor(arg)
if arg == nil or arg == '' then
Line 78:
--- Set the background color of the header
-- @param arg string
--
-- CSS "background-color" property, not nil or empty
-- @return self
--
function InfoboxBuilder:setHeaderBackgroundColor(arg)
if arg == nil or arg == '' then
Line 99:
-- Same as setHeaderBackgroundColor
-- @return self
--
function InfoboxBuilder:setHeaderColors(arg)
if arg == nil then
Line 112:
--- Sets the infobox params
-- @
--
--
--
--
--
--
--
--
--
-- @return self
--
function InfoboxBuilder:setParams(...)
for i, v in ipairs(...) do
if v.name == nil and v.name
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[v.name] = {▼
['type'] = type(v.func),▼
func = v.func,▼
default = v.default▼
}▼
table.insert(self.paramnames, v.name)▼
error("func must be of type \"function\", \"table\", or " ..▼
end▼
else▼
error("name cannot be duplicaate")▼
end▼
error("name must not be nil or empty")
end
end
Line 153 ⟶ 150:
end
--- Sets the infobox arguments
-- @param args Frame
-- A frame object, passed in when invoked
-- @return self
-- The current object
function InfoboxBuilder:setArgs(args)
for k,v in pairs(args) do
Line 161 ⟶ 163:
end
--- Gets the content associated with a parameter
function InfoboxBuilder:getContent(v)▼
-- @param param string
-- The param name, not nil or empty
-- @return content string
-- A string containing the content
if param == nil or param == "" then
error("Param must not be nil or empty")
end
local content = '?'
local argparams = self.params[
local arg = self.args[v.content] or self.params[v.content].default or ''▼
if argparams == nil then
error(string.format("No such param: %s", param))
end
if argparams['type'] == 'function' then
content = self.params[
elseif argparams['type'] == 'table' then
content = self.params[
elseif argparams['type'] == 'string' then
content = arg
Line 177 ⟶ 193:
end
--- Adds a header
-- @param arg { content, attr, colspan, rowspan, css }
-- content string or nil The wikitext to be rendered
-- attr {...} or nil The attributes of the cell in table form
-- colspan number or nil The colspan of the cell
-- roswpan number or nil The rowspan of the cell
-- css {...} or nil The css of the cell in table form
-- @return self
-- The current object
function InfoboxBuilder:addHeader(arg)
local _cell = self.infobox:tag('tr'):tag('th')
Line 203 ⟶ 228:
end
--- Adds an image, or switchable images
-- tag "artd" or "td" The
-- content string The
-- title string or nil The
-- @return self
-- The current object
function InfoboxBuilder:addImage(...)
local argt = ...
Line 211 ⟶ 240:
local _cell = self.infobox:tag('tr'):tag('td')
local content = '?'
if #argt < 2 then
if v.tag == 'argtd' then
content = self:getContent(content)
end
else
local t = {}
for i, v in ipairs(argt) do
local c = v.content
table.insert(t, i, v.title .. "=" .. self:getContent(v))▼
if v.tag == 'argtd' then
c = self:getContent(c)
end
▲ content = mw.getCurrentFrame()
▲ }
end
Line 234 ⟶ 270:
end
--- Adds a row, with columns up to 30 columns spanned
-- @param ... { { tag, content, attr, colspan, rowspan, css }, ... }
-- @return self
-- The current object
function InfoboxBuilder:addRow(...)
local _row = self.infobox:tag('tr')
|