模組:Airport destination list
![文档图示](http://images.weserv.nl/?url=//upload.wikimedia.org/wikipedia/commons/thumb/4/43/Test_Template_Info-Icon_-_Version_%282%29.svg/50px-Test_Template_Info-Icon_-_Version_%282%29.svg.png)
您可能想要创建本Scribunto模块的文档。 编者可以在本模块的沙盒 (创建 | 镜像)和测试样例 (创建)页面进行实验。 请在/doc子页面中添加分类。本模块的子页面。 |
local p = {}
local function isnotempty(s)
return s and s:match( '^%s*(.-)%s*$' ) ~= ''
end
function p.table(frame)
local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
local cols
if isnotempty(args['4thcoltitle']) and isnotempty(args['3rdcoltitle']) then
cols = 4
elseif isnotempty(args['3rdcoltitle']) then cols = 3
else cols = 2
end
-- compute the maximum cell index
local cellcount = 0
for k, v in pairs( args ) do
if type( k ) == 'number' and isnotempty(v) then
cellcount = math.max(cellcount, k)
end
end
-- compute the number of rows
local rows = math.ceil(cellcount / cols)
-- create the root table
local root = mw.html.create('table')
root
:addClass('wikitable')
:addClass('sortable')
:css('font-size', '85%')
-- add the header row
local row = root:tag('tr')
local cell= row:tag('th')
cell:wikitext('航空公司')
cell= row:tag('th')
cell:addClass('unsortable')
cell:wikitext('目的地')
if (isnotempty(args['3rdcoltitle'])) then
cell= row:tag('th')
cell:css('width','10%')
if (isnotempty(args['3rdcolunsortable'])) then
cell:addClass('unsortable')
end
cell:wikitext(args['3rdcoltitle'])
end
if (isnotempty(args['4thcoltitle'])) then
cell= row:tag('th')
if (isnotempty(args['4thcolunsortable'])) then
cell:addClass('unsortable')
end
cell:wikitext(args['4thcoltitle'])
end
-- loop over rows
for j=1,rows do
row = root:tag('tr')
for i=1,cols do
cell= row:tag('td')
if (i > 2) then cell:css('text-align','center') end
cell:wikitext(args[cols*(j - 1) + i] or '')
end
end
-- return the root table
return tostring(root)
end
return p