Module:表格
跳转到导航
跳转到搜索
- 子页面模块
- Module:表格/doc
- Module:表格/固体
- Module:表格/太空地点
- Module:表格/太空矿带
- Module:表格/太空遗迹
- Module:表格/工艺品
- Module:表格/建筑配方
- Module:表格/影响页面
- Module:表格/气体
- Module:表格/流星伤害
- Module:表格/流星掉落效果
- Module:表格/流星爆炸效果
- Module:表格/流星类型
- Module:表格/流星结块效果
- Module:表格/流星雨事件
- Module:表格/流星雨季
- Module:表格/液体
- Module:表格/液温调节器冷却剂
- Module:表格/温度调节器冷却剂
- Module:表格/版本维护
- Module:表格/蓝图
- Module:表格/译名
- Module:表格/通用建造材料属性
- Module:表格/配方
- Module:表格/间歇泉
- Module:表格/间歇泉产率
- Module:表格/食物
-- Module:表格
local p = {}
local fstr = mw.ustring.format -- shortcut for formattig a string
-- test by: = p.table({{1,2,3},{4,5,6}})
-- test by: = p.table({{1,2,3},{4,{5, {['data-sort-value'] = 6}},6}})
function p.table(tb, args)
args = type(args) == "table" and args or {}
local out = {}
for _, row in ipairs(tb) do
local rowOut = {}
for i, cell in ipairs(row) do
local content
local attrs
if type(cell) == "table" then
content = cell[1]
attrs = mw.clone(cell[2])
else
content = cell
attrs = {}
end
local sty = args[fstr("style col %d", i)]
if sty ~= nil and attrs.style == nil then
attrs.style = sty
end
local cellCode = ""
if type(next(attrs)) ~= "nil" then
cellCode = '| '
for k, v in pairs(attrs) do
cellCode = fstr('%s%s="%s" ', cellCode, k, v)
end
end
cellCode = fstr('%s| %s\n', cellCode, content)
table.insert(rowOut, cellCode)
end
table.insert(out, fstr("|-\n%s", table.concat(rowOut, "")))
end
return mw.getCurrentFrame():preprocess(table.concat(out, ""))
end
function p.error(msg, args)
local out = "|-\n|"
local nCol = args and args.nCol and tonumber(args.nCol)
if nCol then out = fstr('%s colspan="%d" |', out, nCol) end
return fstr("%s(%s)", out, msg)
end
function p.test(frame) return p.table({{1, 2, 3}, {4, 5, 6}}) end
return p