From WikiChip
Difference between revisions of "Module:comp"

 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
function split(str, sep)
 +
        if sep == nil then
 +
                sep = "%s"
 +
        end
 +
        local t={} ; i=1
 +
        for str in string.gmatch(str, "([^"..sep.."]+)") do
 +
                t[i] = str:match "^%s*(.-)%s*$"
 +
                i = i + 1
 +
        end
 +
        return t
 +
end
 +
 +
 
local m = {}
 
local m = {}
  
 
function m.mpu_comp(frame)
 
function m.mpu_comp(frame)
 +
  local wikichip = require("Module:wikichip")
 
 
 
   if not frame.args.list then
 
   if not frame.args.list then
Line 8: Line 22:
 
 
 
   local list = split(frame.args.list, ',')
 
   local list = split(frame.args.list, ',')
   local s
+
   local chips = { }
   for chip in list do
+
 
     s = s .. "<br>\n*" .. chip
+
   for key, chip_name in pairs(list) do
 +
    local chip = wikichip:new(chip_name)
 +
    if not chip.is_valid() then
 +
     return '<strong>"' .. chip_name .. '"</strong> cannot be found.';
 +
end
 +
chips[#chips+1] = chip
 
   end
 
   end
 +
 
 +
  local table = mw.html.create('table')
 +
  :attr('style', 'border: 1px solid black; border-collapse: collapse;')
 +
local row
 +
 +
-- models
 +
row = table:tag('tr')
 +
row:tag('td')
 +
:attr('style', 'border: 1px solid black; padding: 15px; text-align: center;'):wikitext('&nbsp;')
 +
for key,val in pairs(chips) do
 +
row:tag('td')
 +
:attr('style', 'border: 1px solid black; padding: 15px; text-align: center;')
 +
:wikitext(val.name())
 +
end
 +
 +
-- designer
 +
row = table:tag('tr')
 +
row:tag('td')
 +
:attr('style', 'border: 1px solid black; padding: 1px; text-align: center;'):wikitext('Designer')
 +
for key,val in pairs(chips) do
 +
row:tag('td')
 +
:attr('style', 'border: 1px solid black; padding: 1px; text-align: center;')
 +
:wikitext('[[' .. val.designer() .. ']]')
 +
end
 +
 +
-- manufacturer
 +
row = table:tag('tr')
 +
row:tag('td')
 +
:attr('style', 'border: 1px solid black; padding: 1px; text-align: center;'):wikitext('Manufacturer')
 +
for key,val in pairs(chips) do
 +
row:tag('td')
 +
:attr('style', 'border: 1px solid black; padding: 1px; text-align: center;')
 +
:wikitext('[[' .. val.manufacturer() .. ']]')
 +
end
 +
 
 +
 
 +
  return table
 
end
 
end
  
 
return m
 
return m

Latest revision as of 04:00, 29 June 2017

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

function split(str, sep)
        if sep == nil then
                sep = "%s"
        end
        local t={} ; i=1
        for str in string.gmatch(str, "([^"..sep.."]+)") do
                t[i] = str:match "^%s*(.-)%s*$"
                i = i + 1
        end
        return t
end


local m = {}

function m.mpu_comp(frame)
  local wikichip = require("Module:wikichip")
	
  if not frame.args.list then
    return 'Error: Missing chip list to compare!'
  end
	
  local list = split(frame.args.list, ',')
  local chips = { }
  
  for key, chip_name in pairs(list) do
    local chip = wikichip:new(chip_name)
    if not chip.is_valid() then
    	return '<strong>"' .. chip_name .. '"</strong> cannot be found.';
	end
	chips[#chips+1] = chip
  end
  
  local table = mw.html.create('table')
  				:attr('style', 'border: 1px solid black; border-collapse: collapse;')
	local row
	
	-- models
	row = table:tag('tr')
	row:tag('td')
			:attr('style', 'border: 1px solid black; padding: 15px; text-align: center;'):wikitext('&nbsp;')
	for key,val in pairs(chips) do
		row:tag('td')
			:attr('style', 'border: 1px solid black; padding: 15px; text-align: center;')
			:wikitext(val.name())
	end
	
	-- designer
	row = table:tag('tr')
	row:tag('td')
			:attr('style', 'border: 1px solid black; padding: 1px; text-align: center;'):wikitext('Designer')
	for key,val in pairs(chips) do
		row:tag('td')
			:attr('style', 'border: 1px solid black; padding: 1px; text-align: center;')
			:wikitext('[[' .. val.designer() .. ']]')
	end
	
	-- manufacturer
	row = table:tag('tr')
	row:tag('td')
			:attr('style', 'border: 1px solid black; padding: 1px; text-align: center;'):wikitext('Manufacturer')
	for key,val in pairs(chips) do
		row:tag('td')
			:attr('style', 'border: 1px solid black; padding: 1px; text-align: center;')
			:wikitext('[[' .. val.manufacturer() .. ']]')
	end
  
  
  return table
end

return m