From WikiChip
Module:comptable
Revision as of 06:42, 22 August 2017 by David (talk | contribs)

Documentation for this module may be created at Module:comptable/doc

local p = {}

function p.main(frame)
    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
    else
        origArgs = frame
    end
    
    local r = ''
    
    for i = 2, 30 do
    	local val = origArgs[i]
		if not val then break end
		if string.find(val, ":") then
			r = r .. string.gsub(val, "(%d+):(.+)", '<th colspan="%1">%2</th>')
		else
			r = r .. '<th>' .. val .. '</th>'
		end
	end

	return '<tr class="comptable-header"><th>&nbsp;</th>' .. r .. '</tr>'
end

function p.cols(frame)
    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
    else
        origArgs = frame
    end
    
    local r = ''
    
    for i = 2, 30 do
    	local val = origArgs[i]
		if not val then break end
		if string.match(val, '^%.+') then
			r = r .. '<th data-sort-type="number">' .. string.sub(val, 2) .. '</th>'
		elseif string.match(val, '^\$.+') then
			r = r .. '<th>' .. val .. '</th>'
		end
	end

	return '<tr class="comptable-header"><th class="unsortable">Model</th>' .. r .. '</tr>'
end

return p