From WikiChip
Difference between revisions of "Module:expansions"
(8 intermediate revisions by the same user not shown) | |||
Line 33: | Line 33: | ||
local entry = mw.html.create('div') | local entry = mw.html.create('div') | ||
− | entry | + | entry:attr('class', 'spec-box-entry') |
− | |||
if not has_arg('type') then | if not has_arg('type') then | ||
Line 54: | Line 53: | ||
+ (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) | ||
− | |||
t:tag('td'):attr('rowspan', n):wikitext("'''PCIe'''") | t:tag('td'):attr('rowspan', n):wikitext("'''PCIe'''") | ||
− | + | local subobject = "|io_pcie_revision=" .. arg('pcie revision') | |
t:tag('td'):wikitext("'''Revision:''' " .. arg('pcie revision')) | t:tag('td'):wikitext("'''Revision:''' " .. arg('pcie revision')) | ||
if has_arg('pcie lanes') then | if has_arg('pcie lanes') then | ||
tbl:tag('tr'):tag('td'):wikitext("'''Max Lanes:''' " .. arg('pcie lanes')) | tbl:tag('tr'):tag('td'):wikitext("'''Max Lanes:''' " .. arg('pcie lanes')) | ||
− | + | subobject = subobject .. "\n|io_pcie_max_lanes=" .. arg('pcie lanes') | |
− | |||
end | end | ||
Line 70: | Line 67: | ||
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')) | ||
− | + | subobject = subobject .. "\n|io_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)) | ||
− | + | subobject = subobject .. "\n|io_pcie_config=" .. arg('pcie config ' .. i) | |
end | end | ||
end | end | ||
end | end | ||
− | expansion.frame:preprocess( | + | expansion.frame:preprocess("{{#subobject:pcie\n" .. subobject .. "\n}}") |
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) |
Latest revision as of 16:49, 27 December 2019
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('class', 'spec-box-entry')
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)
t:tag('td'):attr('rowspan', n):wikitext("'''PCIe'''")
local subobject = "|io_pcie_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'))
subobject = subobject .. "\n|io_pcie_max_lanes=" .. arg('pcie lanes')
end
if has_arg('pcie config') then
local pcieconf = tbl:tag('tr'):tag('td')
pcieconf:wikitext("'''Configuration:''' " .. arg('pcie config'))
subobject = subobject .. "\n|io_pcie_config=" .. arg('pcie config')
for i = 2, 10 do
if has_arg('pcie config ' .. i) then
pcieconf:wikitext(', ' .. arg('pcie config ' .. i))
subobject = subobject .. "\n|io_pcie_config=" .. arg('pcie config ' .. i)
end
end
end
expansion.frame:preprocess("{{#subobject:pcie\n" .. subobject .. "\n}}")
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