模块:收纳表
外观
此模块的文档可以在模块:收纳表/doc创建
--处理可选择人名
function renderSelect(tabIndices, args)
local splitCount = tonumber(args['splitCount'])
local tabs_pages = mw.html.create('div')
:addClass('tabs_pages')
:css('display: grid')
:css('grid-template-columns', string.rep('1fr ', splitCount))
for i, tabIndex in ipairs(tabIndices) do
tabs_pages:node('strong')
:addClass('tab')
:wikitext(args['tab' .. tabIndex])
if (i-1)%splitCount==0 then mainDiv:tag('br') end
end
return tabs_pages
end
--处理感言内容
function renderContent(tabIndices, args)
local tabs_contents = mw.html.create('div')
:addClass('tabs-contents')
for i, tabIndex in ipairs(tabIndices) do
tabs_contents:node('div')
:addClass('tab-c')
:wikitext(args['content' .. tabIndex])
end
return tabs_contents
end
function p.testimonials(frame)
local args, tabIndices = {}, {}
--获取页面传来的参数,而非模板本身的参数
local parent_args = frame:getParent().args;
--可自定义每行几人,预设5
if args['splitCount'] == nil then args['splitCount'] = 5 end
--将获取的参数传给args
for k, v in pairs(parent_args) do
if v ~= 'nil' then args[k] = v end --避免空的参数
end
--|tab(x) 的数字可能非123...,可能是012...、037...等
--用于处理上述情况
for k, v in pairs(args) do
local tabIndex = ('' .. k):match('^tab(%d+)$')
if tabIndex then table.insert(tabIndices, tonumber(awardNum)) end
end
table.sort(tabIndices)
--处理勋章
local mainDiv = mw.html.create('div')
:addClass('tabs-container')
mainDiv:node(renderSelect(tabIndices, args))
mainDiv:node(renderContent(tabIndices, args))
return tostring(mainDiv)
end
return p