From WikiChip
Difference between revisions of "Module:expansions"

Line 60: Line 60:
 
end
 
end
 
 
return box:tag('div'):attr('style', 'min-width: 250px; display: inline-block;'):wikitext(tbl)
+
return box:tag('div'):attr('style', 'min-width: 250px; display: inline-block;'):node(tbl)
 
end
 
end
  
 
return expansion
 
return expansion

Revision as of 20:43, 16 August 2017

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

local expansion = {}
local origArgs

function has_arg(name)
	-- The argument can exist and be empty or not exist at all
	return string.len(origArgs[name] or '') > 0
end

function arg(name)
	return origArgs[name]
end

function single_entry(box, argn)
	if has_arg(argn) then
		box:tag('div'):attr('style', 'min-width: 250px; display: inline-block;'):wikitext("'''" .. argn .. ":''' " .. arg(argn))
	end
end

function expansion.expansion(frame)

    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
    else
        origArgs = frame
    end

    local entry = mw.html.create('div')

    entry
        :attr('style', 'background:#f9f9f9; margin: 10px 2px 10px 2px; padding: 5px; border: 1px solid #a7d7f9;')
        
    if not has_arg('type') then
    	return "* ERROR: '''WRONG <code>type</code> parameter!'''"	
	end
	
	if arg('type') == 'PCIe' then
		return 	expansion.pcie(entry)
	end
   
   return entry     
end

function expansion.pcie(box)
	local tbl = mw.html.create('table')
	local t = tbl:tag('tr')
	local n = (has_arg('pcie revision') and 1)
				+ (has_arg('pcie lanes') and 1)
				+ (has_arg('pcie config') and 1) 
	
	t:tag('td'):attr('rowspan', n):wikitext("'''PCIe'''")
	
	t:tag('td'):wikitext("'''Revision:''' " .. arg('pcie revision'))
	
	if has_arg('pcie lanes') then
		tbl:tag('tr'):tag('td'):wikitext("'''Max Lanes:''' " .. arg('pcie lanes'))
	end
	
	if has_arg('pcie config') then
		tbl:tag('tr'):tag('td'):wikitext("'''Max Lanes:''' " .. arg('pcie config'))
	end
	
	return box:tag('div'):attr('style', 'min-width: 250px; display: inline-block;'):node(tbl)
end

return expansion