From WikiChip
Difference between revisions of "Module:expansions"
Line 54: | Line 54: | ||
+ (has_arg('pcie lanes') and 1 or 0) | + (has_arg('pcie lanes') and 1 or 0) | ||
+ (has_arg('pcie config') and 1 or 0) | + (has_arg('pcie config') and 1 or 0) | ||
+ | local suboject = '' | ||
t:tag('td'):attr('rowspan', n):wikitext("'''PCIe'''") | t:tag('td'):attr('rowspan', n):wikitext("'''PCIe'''") | ||
+ | suboject = ' | revision = ' .. arg('pcie revision') | ||
t:tag('td'):wikitext("'''Revision:''' " .. arg('pcie revision')) | t:tag('td'):wikitext("'''Revision:''' " .. arg('pcie revision')) | ||
Line 62: | Line 64: | ||
tbl:tag('tr'):tag('td'):wikitext("'''Max Lanes:''' " .. arg('pcie lanes')) | tbl:tag('tr'):tag('td'):wikitext("'''Max Lanes:''' " .. arg('pcie lanes')) | ||
expansion.set_val('max pcie lanes', arg('pcie lanes')) | expansion.set_val('max pcie lanes', arg('pcie lanes')) | ||
+ | suboject = suboject .. ' | max pcie lanes = ' .. arg('pcie lanes') | ||
end | end | ||
Line 67: | Line 70: | ||
local pcieconf = tbl:tag('tr'):tag('td') | local pcieconf = tbl:tag('tr'):tag('td') | ||
pcieconf:wikitext("'''Configuration:''' " .. arg('pcie config')) | pcieconf:wikitext("'''Configuration:''' " .. arg('pcie config')) | ||
+ | suboject = suboject .. ' | pcie config = ' .. arg('pcie config') | ||
for i = 2, 10 do | for i = 2, 10 do | ||
if has_arg('pcie config ' .. i) then | if has_arg('pcie config ' .. i) then | ||
pcieconf:wikitext(', ' .. arg('pcie config ' .. i)) | pcieconf:wikitext(', ' .. arg('pcie config ' .. i)) | ||
+ | suboject = suboject .. ' | pcie config = ' .. arg('pcie config') | ||
end | end | ||
end | end | ||
end | end | ||
+ | |||
+ | expansion.frame:preprocess('{{#subobject: pcie' .. suboject .. '}}') | ||
return box:tag('div'):attr('style', 'min-width: 100px; padding: 10px; display: inline-block;'):node(tbl) | return box:tag('div'):attr('style', 'min-width: 100px; padding: 10px; display: inline-block;'):node(tbl) |
Revision as of 18:00, 22 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 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
if arg('type') == 'USB' then return expansion.usb(entry) end
if arg('type') == 'SATA' then return expansion.sata(entry) end
if arg('type') == 'HSIO' then return expansion.hsio(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 or 0)
+ (has_arg('pcie lanes') and 1 or 0)
+ (has_arg('pcie config') and 1 or 0)
local suboject = ''
t:tag('td'):attr('rowspan', n):wikitext("'''PCIe'''")
suboject = ' | revision = ' .. arg('pcie revision')
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'))
suboject = suboject .. ' | 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'))
suboject = suboject .. ' | pcie config = ' .. arg('pcie config')
for i = 2, 10 do
if has_arg('pcie config ' .. i) then
pcieconf:wikitext(', ' .. arg('pcie config ' .. i))
suboject = suboject .. ' | pcie config = ' .. arg('pcie config')
end
end
end
expansion.frame:preprocess('{{#subobject: pcie' .. suboject .. '}}')
return box:tag('div'):attr('style', 'min-width: 100px; padding: 10px; display: inline-block;'):node(tbl)
end
function expansion.usb(box)
local tbl = mw.html.create('table')
local t = tbl:tag('tr')
local n = (has_arg('usb revision') and 1 or 0)
+ (has_arg('usb ports') and 1 or 0)
+ (has_arg('usb rate') and 1 or 0)
+ (has_arg('usb extra') and 1 or 0)
t:tag('td'):attr('rowspan', n):wikitext("'''USB'''")
t:tag('td'):wikitext("'''Revision:''' " .. arg('usb revision'))
for i = 2, 10 do
if has_arg('usb revision ' .. i) then
pcieconf:wikitext(', ' .. arg('usb revision ' .. i))
end
end
if has_arg('usb ports') then
tbl:tag('tr'):tag('td'):wikitext("'''Max Ports:''' " .. arg('usb ports'))
expansion.set_val('max usb ports', arg('usb ports'))
end
if has_arg('usb rate') then
tbl:tag('tr'):tag('td'):wikitext("'''Rate:''' " .. arg('usb rate'))
end
if has_arg('usb extra') then
tbl:tag('tr'):tag('td'):wikitext(arg('usb extra'))
end
return box:tag('div'):attr('style', 'min-width: 100px; padding: 10px; display: inline-block;'):node(tbl)
end
function expansion.sata(box)
local tbl = mw.html.create('table')
local t = tbl:tag('tr')
local n = (has_arg('sata revision') and 1 or 0)
+ (has_arg('sata ports') and 1 or 0)
t:tag('td'):attr('rowspan', n):wikitext("'''SATA'''")
t:tag('td'):wikitext("'''Revision:''' " .. arg('sata revision'))
for i = 2, 10 do
if has_arg('sata revision ' .. i) then
pcieconf:wikitext(', ' .. arg('sata revision ' .. i))
end
end
if has_arg('sata ports') then
tbl:tag('tr'):tag('td'):wikitext("'''Max Ports:''' " .. arg('sata ports'))
expansion.set_val('max sata ports', arg('sata ports'))
end
return box:tag('div'):attr('style', 'min-width: 100px; padding: 10px; display: inline-block;'):node(tbl)
end
function expansion.hsio(box)
local tbl = mw.html.create('table')
local t = tbl:tag('tr')
t:tag('td'):attr('rowspan', n):wikitext("'''HSIO'''")
t:tag('td'):wikitext("'''Max Lanes:''' " .. arg('hsio lanes'))
expansion.set_val('max hsio lanes', arg('hsio lanes'))
return box:tag('div'):attr('style', 'min-width: 100px; padding: 10px; display: inline-block;'):node(tbl)
end
return expansion