模組:MakeTable/examples

文档图示 模块文档[创建]
local MakeTable = require("Module:MakeTable")
local R = function(rstr)
	return function ()
		return rstr
	end
end


local examples = {
	basic = R(MakeTable({
		content = {
			{"Content1.1","Content1.2"},
			{"Content2.1","Content2.2"}
		}
	})),
	wikitable = R(MakeTable({
		class = {"wikitable"},
		content = {
			{"Content1.1","Content1.2"},
			{"Content2.1","Content2.2"}
		}
	})),
	wikitable_sortable_title = R(MakeTable({
		class = {"wikitable","sortable"},
		titles = {"title1","title2"},
		content = {
			{"Content1.1","Content1.2"},
			{"Content2.1","Content2.2"}
		}
	})),
	wikitable_caption = R(MakeTable({
		class = {"wikitable"},
		caption = "标题",
		content = {
			{"Content1.1","Content1.2"},
			{"Content2.1","Content2.2"}
		}
	})),
}

local p = {}
p.all = function()
	local force_order = {"basic","wikitable","wikitable_sortable_title","wikitable_caption"}
	local FOFVtable = {}
	for y,x in pairs(force_order) do
		FOFVtable[x] = y
	end
	local cont = mw.html.create( 'div' )
	for _,y in ipairs(force_order) do
		cont:tag("h3"):wikitext(y)
		cont:node(examples[y]())
	end
	for x,y in pairs(examples) do
		if not FOFVtable[x] then
			cont:tag("h3"):wikitext(x)
			cont:node(y())
		end
	end
	return tostring(cont)
end

for x,y in pairs(examples) do
	p[x] = y
end

return p