Module:Porter items

--

local p = {}

-- mw.loadData would be better but it can't handle it (#data.items[1] == 0 with mw.loadData) local data = require('Module:Porter_items/data')

function p.main(frame) local max_items = 0 for _, items in ipairs(data.items) do		max_items = math.max(max_items, #items) end local max_col_items = math.ceil(max_items / 2) local cols = #data.items local should_split = {} for _, items in ipairs(data.items) do		local split = #items > max_col_items table.insert(should_split, split) if split then cols = cols + 1 end end local t = mw.html.create('table') :addClass('wikitable mw-collapsible mw-collapsed') :tag('tr') :tag('th'):attr('colspan', cols):wikitext('List of items'):done :done local tr = t:tag('tr') for i, category in ipairs(data.categories) do		if category ~= 'Other' then category =  .. category ..  end local th = tr:tag('th'):wikitext(category) if should_split[i] then th:attr('colspan', '2') end end local function add_row(tr, items, min, max) local td = tr:tag('td'):css('vertical-align', 'top') for i=min, max do td:wikitext( .. items[i] .. ) td:tag('br') end return td	end tr = t:tag('tr') for i, items in ipairs(data.items) do		local td1 = add_row(tr, items, 1, math.min(#items, max_col_items)) if should_split[i] then local td2 = add_row(tr, items, max_col_items + 1, #items) td1:css('border-right', 'none') td2:css('border-left', 'none') end end return t end

return p