Module:Userbox

local string = require('Module:String') local table = require('Module:Table') local getArgs = require('Module:Arguments').getArgs

local p = {}

local skinDefault = { modern = { id = { background = 'transparent' },		info = { background = 'transparent' }	},	retro = { id = { background = '#542e2e' },		info = { background = '#7a5252' }	} }

function p.create(frame) local args = getArgs(frame) local main, id, info = {}, {}, {} local flavor = args[1] or args['skin'] main.class = args['class'] main.margin = args['margin'] main.style = args['style'] main.float = args['float'] main.border_Width = args['border-width'] main.border_color = args['border-color'] main.height = args['height'] id.id = args['id'] id.width = args['id-width'] id.color = args['id-color'] id.background = args['id-background'] id.align = args['id-align'] id.size = args['id-size'] id.padding = args['id-padding'] id.css = args['id-css'] info.info = args['info'] info.color = args['info-color'] info.background = args['info-background'] info.align = args['info-align'] info.size = args['info-size'] info.padding = args['info-padding'] info.css = args['info-css'] return p._create(flavor, main, id, info) end

function p._create(flavor, main, id, info) local mainStyle, mainStyleOp, idStyle, infoStyle = {}, {}, {}, {} local mainHtml, idHtml, infoHtml local function squash(style) local ret = {} for k,v in pairs(style) do			ret[#ret+1] = ('%s: %s;'):format(k,v) end return table.concat(ret, '') end local sDefault = skinDefault[flavor and flavor:lower] or skinDefault.modern local default = skinDefault.modern mainStyle["width"] = '330px' mainStyle["min-height"] = "90px" mainStyle["margin"] = main.margin or '.1em .1em' mainStyleOp["float"] = main.float or 'left' mainStyleOp["border"] = (main.border_width or '3')..'px solid '..(main.border_color and (main.border_color:lower == 'none' and 'transparent' or main.border_color) or '#292929') mainStyleOp["height"] = (main.height and main.height:match('^%s*(%d+)') or '90')..'px' idStyle["width"] = (id.width and id.width:match('^%s*(%d+)') or '90')..'px' idStyle["color"] = id.color and (id.color:lower == 'none' and 'transparent' or id.color) or 'white' idStyle["background"] = id.background and (id.background:lower == 'none' and 'transparent' or id.background) or sDefault.id.background idStyle["text-align"] = id.align or 'center' idStyle["font-size"] = (id.size and id.size:match('^%s*(%d+)') or '14')..'pt' idStyle["padding"] = id.padding or '0 .9em' idStyle["vertical-align"] = 'middle' infoStyle["color"] = info.color and (info.color:lower == 'none' and 'transparent' or info.color) or 'white' infoStyle["background"] = info.background and (info.background:lower == 'none' and 'transparent' or info.background) or sDefault.info.background infoStyle["text-align"] = info.align or 'left' infoStyle["font-size"] = (info.size and info.size:match('^%s*(%d+)') or '12')..'pt' infoStyle["padding"] = info.padding or '0 .7em' infoStyle["vertical-align"] = 'middle' idHtml = string.wrapHtml(id.id or 'id', 'th', { style = squash(idStyle)..(id.css or '') }) infoHtml = string.wrapHtml(info.info or "info", 'td', { style = squash(infoStyle)..(info.css or '') }) main.style = main.style and squash(mainStyle)..' '..main.style main.class = main.class and 'article-userbox '..main.class or 'article-userbox' mainHtml = string.wrapHtml(idHtml..infoHtml, 'table', { cellspacing = "0", class = main.class, style = main.style or table.merge(mainStyle, mainStyleOp) }) return mainHtml end

return p