Module:Userbox

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

local p = {}

local skinDefault = mw.loadData('Module:Userbox/Skins')

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, idStyle, infoStyle = {}, {}, {} local mainHtml, idHtml, infoHtml main, id, info = main or {}, id or {}, info or {} 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 function e(val) val = string.trim(val and tostring(val) or '') return (val ~= '') and val or nil end local function eval(val, def) val = e(val) return val or def end local function col(val, def) val = e(val) return val and (val:lower == 'none' and 'transparent' or val) or def end local function num(val, def) val = e(val) return val and val:match('^%s*(%d+)') or def end local sDefault = skinDefault[flavor and flavor:lower] or skinDefault.modern local default = skinDefault.modern local function def(ns, attr) return sDefault[ns][attr] or default[ns][attr] end local function get(fn, t, ns, attr) return fn(t[attr], def(ns,attr)) end mainStyle["width"] = '330px' mainStyle["min-height"] = "90px" mainStyle["margin"] = get(eval, main, 'main', 'margin') mainStyle["float"] = get(eval, main, 'main', 'float') mainStyle["border"] = get(num, main, 'main', 'border_width') .. 'px solid ' .. get(col, main, 'main','border_color') mainStyle["height"] = get(num, main, 'main', 'height') .. 'px' idStyle["width"] = get(num, id, 'id', 'width') .. 'px' idStyle["color"] = get(col, id, 'id', 'color') idStyle["background"] = get(col, id, 'id', 'background') idStyle["text-align"] = get(eval, id, 'id', 'align') idStyle["font-size"] = get(num, id, 'id', 'size') .. 'pt' idStyle["padding"] = get(eval, id, 'id', 'padding') idStyle["vertical-align"] = 'middle' infoStyle["color"] = get(col, info, 'info', 'color') infoStyle["background"] = get(col, info, 'info', 'background') infoStyle["text-align"] = get(eval, info, 'info', 'align') infoStyle["font-size"] = get(num, info, 'info', 'size') .. 'pt' infoStyle["padding"] = get(eval, info, 'info', 'padding') 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 = squash(mainStyle) .. (main.style or '') 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 }) return mainHtml end

return p