Jump to content

Module:Userbox

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 17:35, 5 January 2014 (make a start on a replacement for Template:Userbox). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

-- This module implements {{userbox}}.

local getArgs = require('Module:Arguments').getArgs
local htmlBuilder = require('Module:HtmlBuilder')
local catHander = require('Module:Category handler')

local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	local userbox = p.userbox(args)
	local cats = p.categories(args)
	return userbox .. (cats or '')
end

function p.userbox(args)
	-- Calculate border width.
	local borderWidth = args['border-width'] or args['border-s']
	borderWidth = tonumber(borderWidth)
	if not borderWidth or borderWidth < 0 then
		borderWidth = 1
	end

	-- Get border color.
	local borderColor = args['border-color'] or args[1] or args['border-c'] or args['id-c'] or '#999'

	-- Get background color.
	local backgroundColor = args['info-background'] or args[2] or args['info-c'] or '#EEE'

	-- Calculate width.
	local width = 240 - 2 * borderWidth

	-- Build the box.
	local root = htmlBuilder.create('div')
	root
		.css('float', args.float or 'left')
		.css('border', tostring(borderWidth) .. 'px solid ' .. borderColor)
		.css('margin', '1px')
		.css('width', tostring(width) .. 'px')
		.addClass('wikipediauserbox')
		.addClass(args.bodyclass)
		.tag('table')
			.css('border-collapse', 'collapse')
			.css('width', width)
			.css('margin-bottom', '0')
			.css('background', backgroundColor)
	
	return tostring(root)
end

function p.categories(args)
end

return p