Jump to content

This site is currently in alpha, so you will run into rough edges.

Please send feedback or ideas to connect@deeptech.wiki

Module:InfoboxMinimal

From The Deep Tech Wiki
Revision as of 05:52, 9 November 2025 by C (talk | contribs) (Created page with "-- Module:InfoboxMinimal local p = {} local function isBlank(s) if s == nil then return true end s = tostring(s) return mw.text.trim(s) == '' end local function addRow(tbl, label, data) if isBlank(data) then return end local tr = tbl:tag('tr') tr:tag('th') :attr('scope', 'row') :addClass('infobox-label') :wikitext(label or '') tr:tag('td') :addClass('infobox-data') :wikitext(data) end function p.infobox(frame) -- Prefer parent args so wrapper templat...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:InfoboxMinimal/doc

-- Module:InfoboxMinimal
local p = {}

local function isBlank(s)
	if s == nil then return true end
	s = tostring(s)
	return mw.text.trim(s) == ''
end

local function addRow(tbl, label, data)
	if isBlank(data) then return end
	local tr = tbl:tag('tr')
	tr:tag('th')
		:attr('scope', 'row')
		:addClass('infobox-label')
		:wikitext(label or '')
	tr:tag('td')
		:addClass('infobox-data')
		:wikitext(data)
end

function p.infobox(frame)
	-- Prefer parent args so wrapper templates work naturally
	local args = frame:getParent() and frame:getParent().args or frame.args

	-- Table wrapper
	local classes = 'infobox'
	if not isBlank(args.bodyclass) then
		classes = classes .. ' ' .. tostring(args.bodyclass)
	end
	local root = mw.html.create('table')
		:addClass(classes)
		:attr('role', 'presentation')

	-- Title
	local title = args.title or args.name or mw.title.getCurrentTitle().baseText
	root:tag('caption')
		:addClass('infobox-title')
		:wikitext(title)

	-- Rows: scan a reasonable range; stops naturally when dataN is blank
	for i = 1, 100 do
		addRow(root, args['label' .. i], args['data' .. i])
	end

	return tostring(root)
end

return p