From WikiChip
Module:expansions
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 expansion.set_val(prop, val)
expansion.frame:preprocess('{{#set: ' .. prop .. '=' .. val .. '}}')
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)
expansion.frame = 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; min-width: 100px;')
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'))
expansion.set_val('max pcie lanes', arg('pcie lanes'))
end
if has_arg('pcie config') then
local pcieconf = tbl:tag('tr'):tag('td')
pcieconf:wikitext("'''Configuration:''' " .. arg('pcie config'))
for i = 2, 10 do
if has_arg('pcie config ' .. i) then
pcieconf:wikitext(', ' .. arg('pcie config ' .. i))
end
end
end
return box:tag('div'):attr('style', 'min-width: 250px; display: inline-block;'):node(tbl)
end
return expansion