打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
登录后可编辑和发表评论。

Module:Userbox

来自Vocawiki

本模板用于制作用户页面个人信息展示的用户框;具体使用方法请参见帮助:用户框

本模板在Vocawiki已完全重构,不兼容原萌百的参数,导入自萌百的用户框需要自行修改。

无描述。

模板参数[编辑模板数据]

此模板首选参数换行的代码块格式。

参数描述类型状态
左侧图片/图标/文字1

无描述

示例值
[[File:Vocawiki logo.svg|36x36px|link=]]
内容必需
右侧正常文本2

无描述

示例值
这位用户是Vocawiki编者
单行文本必需
右侧说明文本3

无描述

单行文本可选
背景颜色bg

无描述

示例值
#39c5bb
字符串可选
边框颜色bd

无描述

示例值
#00b8c6
字符串可选
local p = {}
local getArgs = require('Module:Arguments').getArgs
local acandy = require('Module:ACandy')
local a, Fragment, Raw = acandy.a, acandy.Fragment, acandy.Raw
local div, tr, td = a.div, a.tr, a.td

local function make_block(props, class)
	return td[class or ''] {
		style =
			(props.width and 'width:'..props.width..'px; ' or '')
		 .. 'background:'..props.background..'; '
		 .. 'font-size:'..props.size..'pt; '
		 .. 'line-height:'..props.line_height..'; '
		 .. 'color:'..props.color..';'
		 .. (add_styles or ''),
		 Raw(props.content)
	}
end

local function build_blocks(mode, logo, info, logo2)
	local blocks = Fragment()
	if mode == "double" then
		blocks:insert(logo)
		blocks:insert(info)
		blocks:insert(logo2)
	elseif mode == "reverse" then
		blocks:insert(info)
		blocks:insert(logo)
	else
		blocks:insert(logo)
		blocks:insert(info)
	end
	return blocks
end

function p.main(frame)
	local args = getArgs(frame)
	local function get_by_aliases(...)
		local n = select('#', ...)
		for i = 1, n do
			local key = select(i, ...)
			local item = args[key]
			if item ~= nil then
				return item
			end
		end
		return nil
	end

	local mode = args['mode'] or 'default';
	local double = (mode == 'double');
	local props = {
		float            = args['float'] or 'left',
		display          = args['display'],
		border_color     = get_by_aliases('border-color', 1, 'border-c', 'id-c') or '#999',
		border_image     = args['border-image'],

		logo = {
			width       = get_by_aliases('id1-w', 'id-w')                       or '45',
			background  = get_by_aliases('id1-c', 'id-c', 1, 'logo-background') or '#DDD',
			size        = get_by_aliases('id1-s', 'id-s', 5, 'logo-size')       or '14',
			line_height = get_by_aliases('id1-lh', 'id-lh')                     or '1em',
			color       = get_by_aliases('id1-fc', 'id-fc', 'logo-color')       or 'black',
			content     = get_by_aliases('id1', 'id', 3, 'logo')                or 'id',
		},

		info = {
			background  = get_by_aliases('info-background', 2, 'info-c') or '#EEE',
			size        = get_by_aliases('info-size', 'info-s')          or '9',
			line_height = args['info-lh']                                or '1.25em',
			color       = get_by_aliases('info-color', 8, 'info-fc')     or 'black',
			content     = get_by_aliases('info', 4)                      or "''info''",
		},

		logo2 = double and {
			width       = args['id2-w']                                  or '45',
			background  = get_by_aliases('id2-c', 7, 'logo-background')  or '#DDD',
			size        = get_by_aliases('id2-s', 'logo-size')           or '14',
			line_height = args['id2-lh']                                 or '1em',
			color       = get_by_aliases('id2-fc', 'logo-color')         or 'black',
			content     = get_by_aliases('id2', 5, 'logo')               or 'id2',
		} or nil
	}

	local logo = make_block(props.logo, "userbox-logo")
	local info = make_block(props.info, "userbox-info")
	local logo2 = double and make_block(props.logo2, "userbox-logo") or nil

	return div['userbox'] {
		style =
			'float:'..props.float..'; '
		 .. 'border:1px solid '..props.border_color..'; '
		 .. (props.display and 'display:'..props.display..'; ' or '')
		 .. (props.border_image or ''),
		a.table / tr / build_blocks(mode, logo, info, logo2)
	}
end

return p