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