模块:RichTab
跳到导航
跳到搜索
此模块的文档可以在模块:RichTab/doc创建
local p = {}
function p.render(frame)
local params = {}
if frame:getParent() ~= nil then
frame = frame:getParent()
end
local tabParams = parseTabParams(frame)
if #tabParams == 0 then
return ''
end
if frame.args['class'] then
params.tabClass = frame.args['class']
else
params.tabClass = 'nav-tabs'
end
params.tabBar = {}
params.tabContent = {}
local index = 1
while index < #tabParams do
local id = genId()
local tabIndex = math.ceil(index / 2)
params.tabBar[tabIndex] = {}
params.tabContent[tabIndex] = {}
params.tabBar[tabIndex].tabId = id
params.tabBar[tabIndex].tabName = tabParams[index]
params.tabContent[tabIndex].tabId = id
params.tabContent[tabIndex].tabText = tabParams[index + 1]
index = index + 2
end
params.tabBar[1].tabState = 'active'
params.tabContent[1].tabState = 'active'
return mw.ext.mustache.render('RichTab', params, mw.ext.mustache.PARSE_ARGS)
end
function parseTabParams(frame)
local index = 1
local parsedParams = {}
while frame.args[index] ~= nil do
local continue = false
repeat
if frame.args[index] == '' then
if index % 2 == 0 then
parsedParams[#parsedParams] = nil
else
index = index + 1
end
index = index + 1
continue = true
break;
end
parsedParams[#parsedParams + 1] = frame.args[index]
index = index + 1
continue = true
until true
if not continue then
break
end
end
return parsedParams
end
function genId()
return 'tab-' .. os.clock() * 1e9
end
return p