Module:Ahnentafel

-- -- implements Template:ahnentafel -- local p = {}

function p.chart( frame ) local args = frame.args[1] and frame.args or frame:getParent.args local align = (args['align'] or ''):lower local style = args['style'] or '' if (align == 'right') then style = 'float:right;' .. style elseif (align == 'left') then style = 'float:left;' .. style elseif (align == 'center') then style = 'margin-left:auto; margin-right:auto;' .. style end -- compute the number of levels local maxnum = 0 for k, v in pairs( args ) do		if type(k) == 'number' or (type(k) == 'string' and tonumber(k or '0') > 0) then if tonumber(k) > maxnum then maxnum = k			end end end local levels = math.ceil(math.log(maxnum+1)/math.log(2)) local cells = math.pow(2, levels) - 1 -- build the table local root = mw.html.create('table') root:css('border-spacing', '0') :cssText(style) local cellnum = 0 for l = 1,levels do		local istop = 1 for k = 1,(math.pow(2,l) - 1) do			cellnum = cellnum + 1 local row = root:tag('tr'):css('text-align', 'center') -- top padding local topcell = row:tag('td') topcell:attr('colspan', 2) :attr('rowspan', math.pow(2,levels-l)) -- cell local cell = row:tag('td') cell:attr('colspan',4) :attr('rowspan',2) :wikitext(args[cellnum]) -- bottom padding local botcell = row:tag('td') botcell:attr('colspan', 2) :attr('rowspan', math.pow(2,levels-l)) end end return tostring(root) end

return p