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

Module:OrderedTabs

猛汉♂百科,万男皆可猛的百科全书!转载请标注来源页面的网页链接,并声明引自猛汉百科。内容不可商用。
跳转到导航 跳转到搜索
模块文档  [创建] [刷新]
local p = {}

local umatch = mw.ustring.match

function ExtractTabArgs(t)
	local pack = {}
	local pattern = [=[^(.+)(%d+)$]=]
	for k,v in pairs(t) do
		local typ,ind = umatch(k, pattern)
		mw.log(typ,ind)
		if typ and ind then 
			ind = tonumber(ind) or 0
			typ = string.lower(typ)
			if typ == "bt" or typ == "tab" or typ == "bticon" then 
				if not pack[ind] then pack[ind] = {} end
				pack[ind][typ] = v
			end
		end
	end
	return pack
end

function p.Main(frame)
	local args = (frame:getParent() and frame:getParent().args) or frame.args
	local targs = ExtractTabArgs(args)
	local ret = [[]]
	for k,v in pairs(targs) do
		local index = tonumber(k) or 0
		if index ~= 0 then
			mw.logObject(v)
			if v.bt and v.tab then
				local tabLabel = 
					mw.html.create("div")
					:addClass("TabLabelText")
						:wikitext( (v.bticon or [[]]) .. (v.bt or [[]]) )
					:done()
				local tabContent =
					mw.html.create("div")
					:addClass("TabContentText")
						:wikitext(v.tab or [[]])
					:done()
				local tabRoot = 
					mw.html.create("div")
					:addClass("Tab")
						:node(tabLabel):newline():done()
						:node(tabContent):newline():done()
					:allDone()
				mw.log(tabRoot)
				ret = ret .. tostring(tabRoot) .. "\n"
			end
		end
	end
	return ret
end

return p