memory alpha
Module documentation ()

This module implements {{userbox}}.

Module source

local p = {}

function p.main(frame)
	local args = frame:getParent().args
	local defaultColor = 'red'
	local color = mw.text.trim(args.color or defaultColor)
	local validColors = {'red', 'yellow', 'green', 'cyan', 'blue', 'magenta'}
	local colorIsValid = false
	local align = mw.text.trim(args.align or '')
	local logo = mw.text.trim(args.logo or '')
	local img = mw.text.trim(args.image or '')
	local pd = mw.text.trim(args.pd or '') == '1' and '|link=' or ''
	local size = '|62x62px'
	local label = #img > 0 and '[[File:' .. img .. size .. pd .. ']]' or logo
	local info = mw.text.trim(args.info or '')
	local templatestyles = frame:extensionTag{
		name = 'templatestyles',
		args = {src = 'Module:Userbox/styles.css'}
	}
	
	for k, v in pairs(validColors) do
		if color == v then
			colorIsValid = true
		end
	end
	
	color = colorIsValid and color or defaultColor
	align = #align > 0 and align or 'right'
	
	local userbox = mw.html.create('table')
		:addClass('userbox userbox-' .. color .. ' userbox-' .. align)
		:attr('role', 'presentation')
		:tag('tr')
		:tag('td')
		:addClass('userbox-label')
		:wikitext(label)
		:done()
		:tag('td')
		:addClass('userbox-info')
		:wikitext(info)
		:allDone()
	
	return templatestyles .. tostring(userbox)
end

return p