Module:Infobox
A generic infobox module, that can be utilised by all variants of infoboxes to easily and quickly create infoboxes.
Usage
[edit]See the following example:
local Infobox = require('Module:Infobox')
local p = {}
function p.run(frame)
return Infobox :create(frame, 'rocket')
:name('Vogan')
:image('Liquidlogobig.png')
:header('Team information')
:cell('Location', 'Netherlands')
:cell('Region', 'Europe')
:fcell(Cell:new('Parent company'):options({makeLink = true}):content(args.parent, args.parent2):make())
:header('Links')
:links({twitch = 'TeamLiquid'})
:build()
end
return p
API
[edit]- Programmatic name: Infobox
- create(frame: frame, gameName: string) → Infobox
Initialises the Infobox instance, for the given game
- name(name: string?) → Infobox
Sets the name at the top of the infobox. If nil, uses the pagename.
- image(fileName: string, default: string, size: number) → Infobox
Sets the image given, or the default image if nil. The size var allows for adjusting the size of the image display.
- header(headerText: string, shouldBeVisible: boolean) → Infobox
Creates a header.
shouldBeVisiblemust be set. This argument allows you to make the header conditional on a value not being nil.- cell(description: string, content: string) → Infobox
Creates a cell in the infobox.
- fcell(cell: Cell) → Infobox
Creates a cell in the infobox. Provides more options for formatting.
- centeredCell(content: string) → Infobox
Creates a 'centered' cell, e.g. achievements, caption, etc
- links(links: table) → Infobox
Creates the link icons
- chronology(links: table) → Infobox
Creates chronology for this page, e.g. linking to previous tournaments. Keys in the table should be formatted as such: previous, previous2, previous3, next, next2, next3, etc.
- categories(...: string) → Infobox
Add categories to the infobox (unlimited amount of arguments)
- bottom(wikitext: wikitext) → Infobox
Add content to the bottom of the infobox
- build → wikicode
Creates the full infobox wikicode output
See all our documentation here.
| The above documentation is transcluded from Module:Infobox/doc. (edit | history) Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages. Subpages of this module. |
---
-- @Liquipedia
-- wiki=commons
-- page=Module:Infobox
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
local Array = require('Module:Array')
local Class = require('Module:Class')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Variables = require('Module:Variables')
local WarningBox = require('Module:WarningBox')
local Widget = Lua.import('Module:Widget')
---@class Infobox
---@field frame Frame?
---@field root Html?
---@field adbox Html?
---@field content Html?
---@field warnings string[]
---@field injector WidgetInjector?
local Infobox = Class.new()
--- Inits the Infobox instance
---@param frame Frame
---@param gameName string
---@param forceDarkMode boolean?
---@return self
function Infobox:create(frame, gameName, forceDarkMode)
self.frame = frame
self.root = mw.html.create('div')
:addClass('fo-nttax-infobox-wrapper')
:addClass('infobox-' .. gameName:lower())
self.adbox = mw.html.create('div')
:addClass('fo-nttax-infobox-adbox')
:node(mw.getCurrentFrame():preprocess('<adbox />'))
self.content = mw.html.create('div')
:addClass('fo-nttax-infobox')
if forceDarkMode then
self.root:addClass('infobox-darkmodeforced')
end
self.injector = nil
self.warnings = {}
return self
end
---Adds categories
---@param ... string?
---@return self
function Infobox:categories(...)
Array.forEach({...}, function(cat) return mw.ext.TeamLiquidIntegration.add_category(cat) end)
return self
end
---Sets the widgetInjector
---@param injector WidgetInjector?
---@return self
function Infobox:widgetInjector(injector)
self.injector = injector
return self
end
---Adds custom components after the end the infobox
---@param wikitext string|number|Html|nil
---@return self
function Infobox:bottom(wikitext)
if Logic.isEmpty(wikitext) then
return self
end
self.bottomContent = (self.bottomContent or mw.html.create()):node(wikitext)
return self
end
--- Returns completed infobox
---@param widgets Widget[]
---@return Html
function Infobox:build(widgets)
for _, widget in ipairs(widgets) do
assert(Class.instanceOf(widget, Widget), 'Infobox:build can only accept Widgets')
self.content:node(widget:tryMake(self.injector))
end
self.root:node(self.content)
local isFirstInfobox = Variables.varDefault('is_first_infobox', true)
if isFirstInfobox == true then
self.root:node(self.adbox)
Variables.varDefine('is_first_infobox', 'false')
end
self.root:node(self.bottomContent)
return mw.html.create()
:node(self.root)
:node(WarningBox.displayAll(self.warnings))
end
return Infobox