From WikiChip
Difference between revisions of "Module:comptable"

 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
local p = {}
 
local p = {}
  
function p.main_header(frame)
+
function p.main(frame)
 
     if frame == mw.getCurrentFrame() then
 
     if frame == mw.getCurrentFrame() then
 
         origArgs = frame:getParent().args
 
         origArgs = frame:getParent().args
Line 10: Line 10:
 
     local r = ''
 
     local r = ''
 
      
 
      
     for i = 1, 30 do
+
     for i = 2, 30 do
 
     local val = origArgs[i]
 
     local val = origArgs[i]
 
if not val then break end
 
if not val then break end
 
if string.find(val, ":") then
 
if string.find(val, ":") then
r = r .. string.gsub(val, "(%d+):(%a+)", '<th colspan="%1">%2</th>')
+
r = r .. string.gsub(val, "(%d+):(.+)", '<th colspan="%1">%2</th>')
 
else
 
else
 
r = r .. '<th>' .. val .. '</th>'
 
r = r .. '<th>' .. val .. '</th>'
Line 21: Line 21:
  
 
return '<tr class="comptable-header"><th>&nbsp;</th>' .. r .. '</tr>'
 
return '<tr class="comptable-header"><th>&nbsp;</th>' .. r .. '</tr>'
 +
end
 +
 +
function p.lsep(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" style="text-align: left;">%2</th>')
 +
else
 +
r = r .. '<th style="text-align: left;">' .. 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>'
 +
else
 +
r = r .. '<th>' .. val .. '</th>'
 +
end
 +
end
 +
 +
return '<tr class="comptable-header"><th class="unsortable">Model</th>' .. r .. '</tr>'
 +
end
 +
 +
---------------------------------------------
 +
 +
function p.main2(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="comptable2-header"><th>&nbsp;</th>' .. r .. '</tr>'
 +
end
 +
 +
function p.lsep2(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" style="text-align: left;">%2</th>')
 +
else
 +
r = r .. '<th style="text-align: left;">' .. val .. '</th>'
 +
end
 +
end
 +
 +
return '<tr class="comptable2-header"><th>&nbsp;</th>' .. r .. '</tr>'
 +
end
 +
 +
function p.cols2(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>'
 +
else
 +
r = r .. '<th>' .. val .. '</th>'
 +
end
 +
end
 +
 +
return '<tr class="comptable2-header"><th class="unsortable">Model</th>' .. r .. '</tr>'
 
end
 
end
  
 
return p
 
return p

Latest revision as of 01:27, 28 November 2017

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.lsep(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" style="text-align: left;">%2</th>')
		else
			r = r .. '<th style="text-align: left;">' .. 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>'
		else
			r = r .. '<th>' .. val .. '</th>'
		end
	end

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

---------------------------------------------

function p.main2(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="comptable2-header"><th>&nbsp;</th>' .. r .. '</tr>'
end

function p.lsep2(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" style="text-align: left;">%2</th>')
		else
			r = r .. '<th style="text-align: left;">' .. val .. '</th>'
		end
	end

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

function p.cols2(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>'
		else
			r = r .. '<th>' .. val .. '</th>'
		end
	end

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

return p