Jump to content

Module:Infobox: Difference between revisions

From VassarWiki
vw-border
adding header support
Line 8: Line 8:
:css('font-size', '90%')
:css('font-size', '90%')
:css('background', 'var(--vw-bg-subtle)')
:css('background', 'var(--vw-bg-subtle)')
 
-- Title
-- Title
if args.title and args.title ~= '' then
if args.title and args.title ~= '' then
Line 16: Line 16:
:css('text-align', 'center')
:css('text-align', 'center')
:css('font-size', '115%')
:css('font-size', '115%')
:css('background', 'var(--vw-accent)')
:css('background', 'var(--vw-accent-subtle)')
:css('color', 'var(--vw-bg-page)')
:css('padding', '6px')
:css('padding', '6px')
:css('margin', '12px')
:wikitext(args.title)
:wikitext(args.title)
end
end
Line 45: Line 43:
-- Data rows
-- Data rows
local i = 1
local i = 1
while args['label' .. i] or args['data' .. i] do
while args['label' .. i] or args['data' .. i] or args['header' .. i] do
local label = args['label' .. i]
local header = args['header' .. i]
local data = args['data' .. i]
local label = args['label' .. i]
if data and data ~= '' then
local data   = args['data' .. i]
 
if header and header ~= '' then
root:tag('tr')
:tag('th')
:attr('colspan', '2')
:css('text-align', 'center')
:css('background', 'var(--vw-bg-heading)')
:css('padding', '4px 6px')
:css('font-size', '90%')
:wikitext(header)
elseif data and data ~= '' then
local row = root:tag('tr')
local row = root:tag('tr')
if label and label ~= '' then
if label and label ~= '' then
Line 54: Line 63:
:css('text-align', 'left')
:css('text-align', 'left')
:css('padding', '4px 6px')
:css('padding', '4px 6px')
:css('background', 'var(--vw-bg-subtle)')
:css('width', '45%')
:css('width', '45%')
:wikitext(label)
:wikitext(label)
Line 64: Line 74:
i = i + 1
i = i + 1
end
end
return tostring(root)
return tostring(root)
end
end


return p
return p

Revision as of 01:09, 15 April 2026

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

local p = {}

function p.render(frame)
	local args = frame:getParent().args
	local root = mw.html.create('table')
		:addClass('infobox')
		:css('border', '1px solid var(--vw-border)')
		:css('font-size', '90%')
		:css('background', 'var(--vw-bg-subtle)')
		
-- Title
	if args.title and args.title ~= '' then
		root:tag('tr')
			:tag('th')
				:attr('colspan', '2')
				:css('text-align', 'center')
				:css('font-size', '115%')
				:css('background', 'var(--vw-accent-subtle)')
				:css('padding', '6px')
				:wikitext(args.title)
	end
	
	-- Image
	if args.image and args.image ~= '' then
		local caption = args.caption or ''
		root:tag('tr')
			:tag('td')
				:attr('colspan', '2')
				:css('text-align', 'center')
				:css('padding', '6px')
				:wikitext('[[File:' .. args.image .. '|200px]]')
		if caption ~= '' then
			root:tag('tr')
				:tag('td')
					:attr('colspan', '2')
					:css('text-align', 'center')
					:css('font-size', '85%')
					:css('padding', '2px 6px')
					:wikitext(caption)
		end
	end

	-- Data rows
	local i = 1
	while args['label' .. i] or args['data' .. i] or args['header' .. i] do
		local header = args['header' .. i]
		local label  = args['label' .. i]
		local data   = args['data' .. i]

		if header and header ~= '' then
			root:tag('tr')
				:tag('th')
					:attr('colspan', '2')
					:css('text-align', 'center')
					:css('background', 'var(--vw-bg-heading)')
					:css('padding', '4px 6px')
					:css('font-size', '90%')
					:wikitext(header)
		elseif data and data ~= '' then
			local row = root:tag('tr')
			if label and label ~= '' then
				row:tag('th')
					:css('text-align', 'left')
					:css('padding', '4px 6px')
					:css('background', 'var(--vw-bg-subtle)')
					:css('width', '45%')
					:wikitext(label)
			end
			row:tag('td')
				:css('padding', '4px 6px')
				:attr('colspan', (label and label ~= '') and '1' or '2')
				:wikitext(data)
		end
		i = i + 1
	end
	return tostring(root)
end

return p