七日内新公告:全站维护公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:NavChara

猛汉♂百科,万男皆可猛的百科全书!转载请标注来源页面的网页链接,并声明引自猛汉百科。内容不可商用。
跳转到导航 跳转到搜索
模块文档  [创建] [刷新]
local p = {}
function p.getArg(frame)
	local wrappers = {
		['Template:沙盒'] = true,
		['Template:NavChara'] = true,
	}
	local parent = frame:getParent()
	if parent and wrappers[parent:getTitle()] then
		frame = parent
	end
	return p.main(frame.args)
end
function p.navChara(num, args)--生成单个图组
	local text, imgsrc
	local img = args['img' .. num]
	local size = args['size' .. num] or args.sizes or '60px'
	if img then
		-- 图片数据判定				内部图片   外部图片或自制图形
		imgsrc = mw.title.new('File:'..img).file.exists and '[[File:'..img..'|'..size..']]' or img
	else
		imgsrc = '<div style="height:60px"></div>'
	end
    local link = args['link' .. num] or ''
    local name = args['name' .. num] or nil
    local iclass = args['iclass'.. num] or ''
    local istyle = args['istyle'.. num] or ''
    local boxClass = args['class'.. num] or ''
    local boxStyle = args['style'.. num] or ''
    if args['text' .. num] then
    	text = args['text' .. num]
    else
    	if name ~= nil then
    		text = '[['..link..'|'..name..']]'
    	else
    		text = '[['..link..']]'
    	end
    end
    return '<div class="'..boxClass..'" style="'..boxStyle..'">'..
    	'<div class="'..iclass..'" style="'..istyle..'">'..imgsrc..'</div><br>'..text..
    	'</div>'
end
function p.main(args)
	local class = args.class or ""
	local style = args.style or ""
	local justify = args["排列"] or ""
	local navCharas = {}
    local keys = {}
	--获取以img为前缀参数的数量
	for key, _ in pairs(args) do
		if key:match('^img%d+$') then
			local num = key:match('%d+$')
			table.insert(keys, tonumber(num))
		end
	end
	table.sort(keys)
	--生成navChara表
	for _, num in ipairs(keys) do
		table.insert(navCharas, p.navChara(num, args))
	end
	return '<div class="nav-chara '..class..'" style="justify-content:'..justify..';'..style..'">'..
	table.concat(navCharas, '')..'</div>'
end
return p