Module:Infobox/Basic

From Liquipedia Commons Wiki
Module documentation[view] [edit] [history] [purge]

A generic infobox implementation module, which uses Module:Infobox.

Usage[edit]

See the following example which creates a map infobox:

local BasicInfobox = require('Module:Infobox/Basic')
local Cell = require('Module:Infobox/Cell')
local Class = require('Module:Class')
local Namespace = require('Module:Namespace')
local getArgs = require('Module:Arguments').getArgs

local Map = Class.new(BasicInfobox)

function Map.run(frame)
	local map = Map(frame)
	local args = getArgs(frame)
	local infobox = map.infobox
	infobox:name(self.name)
	infobox:image(args.image, args.defaultImage)
	infobox:centeredCell(args.caption)
	infobox:header('Map Information', true)
	infobox:fcell(Cell:new('Creator'):options({makeLink = true}):content(
		args.creator or args['created-by']):make())
	Map:addCustomCells(infobox, args)
	infobox:bottom(Map.createBottomContent(infobox))

	return infobox:build()
end

return Map

Functions[edit]

Programmatic name: Infobox

getAllArgsForBase(args: table, base: string, options: table) → table

Retrieves a sub table of the args table where the key fits the base with an optionally appended index. The available option "makeLink" allows it to make the retrieved sub table to consist of customizable links.


See all our documentation here.


---
-- @Liquipedia
-- wiki=commons
-- page=Module:Infobox/Basic
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Arguments = require('Module:Arguments')
local Class = require('Module:Class')
local Lua = require('Module:Lua')
local Logic = require('Module:Logic')
local Table = require('Module:Table')

local Info = Lua.import('Module:Info')
local Infobox = Lua.import('Module:Infobox')

---@class BasicInfobox
---@operator call(Frame): BasicInfobox
---@field args table
---@field pagename string
---@field name string
---@field wiki string
---@field infobox Infobox
local BasicInfobox = Class.new(
	function(self, frame)
		self.args = Arguments.getArgs(frame)
		self.pagename = mw.title.getCurrentTitle().text
		self.name = self.args.name or self.pagename
		self.wiki = self.args.wiki or Info.wikiName

		self.infobox = Infobox:create(frame, self.wiki, Logic.readBool(self.args.darkmodeforced))
	end
)

---@param injector WidgetInjector?
---@return self
function BasicInfobox:setWidgetInjector(injector)
	self.infobox:widgetInjector(injector)
	return self
end

--- Allows for overriding this functionality
---Add bottom content below the infobox, e.g. matchtickers
---@return string?
function BasicInfobox:createBottomContent()
	return nil
end

--- Allows for overriding this functionality
---Set wikispecific categories
---@param args table
---@return table
function BasicInfobox:getWikiCategories(args)
	return {}
end

--- Allows for using this for customCells
---Fetches all arguments from the args table for a given base
---@generic K, V
---@param args {[K]: V}
---@param base string
---@param options {makeLink: boolean?}?
---@return V[]
function BasicInfobox:getAllArgsForBase(args, base, options)
	options = options or {}

	local makeLink = Logic.readBool(options.makeLink)
	local foundArgs = {}

	for key, value in Table.iter.pairsByPrefix(args, base, {requireIndex = false}) do
		if makeLink then
			local link = args[key .. 'link'] or value
			value = '[[' .. link .. '|' .. value .. ']]'
		end
		table.insert(foundArgs, value)
	end

	return foundArgs
end

return BasicInfobox