From WikiChip
Difference between revisions of "Module:core"
Line 194: | Line 194: | ||
-- process | -- process | ||
if has_arg('proc') then | if has_arg('proc') then | ||
− | local process = mw.html.create('td'):wikitext('[[ | + | local process = mw.html.create('td'):wikitext('[[process::' .. arg('proc') .. ']]') |
for i = 2, 10 do | for i = 2, 10 do | ||
if not has_arg('proc ' .. i) then break end | if not has_arg('proc ' .. i) then break end |
Revision as of 11:21, 15 July 2017
To add this template, simple add
{{core}}to the page and save. The chip infobox will have a small
[Edit Values]
button at the top-right corner which can be used to add values using a form.
local p = {}
local origArgs
function p.add_file_prefix(str)
if string.match(string.lower(str), '^file:') then
return str
else
return 'File:' .. str
end
end
function p.add_separator(box, title)
box:tag('tr')
:tag('td')
:attr('class', 'header')
:attr('colspan', '2')
:wikitext(title)
end
function add_header(box, str)
box
:tag('tr')
:tag('td')
:attr('class', 'header')
:attr('colspan', '2')
:wikitext(str)
end
function p.add_entry(value, right)
local e = mw.html.create('tr')
e:tag('td')
:attr('class', 'label')
:wikitext(value)
e:node(right)
return e
end
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 p.core(frame)
if frame == mw.getCurrentFrame() then
origArgs = frame:getParent().args
else
origArgs = frame.args
end
local infobox = mw.html.create('table')
infobox
:attr('class', 'infobox')
infobox
:tag('tr')
:tag('td'):attr('colspan', '2')
:tag('small'):attr('style', 'float: right;')
:wikitext('[[Special:FormEdit/core/' .. frame:preprocess('{{FULLPAGENAME}}') .. '|<i class="fa fa-edit"></i>Edit Values]]')
-- header
if has_arg('name') then
infobox
:tag('tr')
:tag('td')
:attr('class', 'header-main')
:attr('colspan', '2')
:wikitext('[[name::' .. arg('name') .. ']]')
end
-- image
for i = 1, 10 do
local name = (i == 1) and "" or " " .. i
if has_arg('image' .. name) then
local image = p.add_file_prefix(arg('image' .. name))
local image_size = has_arg('image' .. name .. ' size') and arg('image' .. name .. ' size') or "200px"
infobox
:tag('tr')
:tag('td')
:attr('style', 'text-align: center;')
:attr('colspan', '2')
:wikitext('[[main image::' .. image .. '| ]][[' .. image .. '|' .. image_size .. ']]')
-- add a caption, if provided
if has_arg('caption' .. name) then
infobox
:tag('tr')
:tag('td')
:attr('style', 'text-align: center;')
:attr('colspan', '2')
:wikitext('[[main image caption::' .. arg('caption' .. name) .. ']]')
end
elseif not has_arg('no image' .. name) then
if i == 1 then
infobox
:tag('tr')
:tag('td')
:attr('style', 'text-align: center;')
:attr('colspan', '2')
:wikitext('[[File:no photo (ic).svg|link=|200px]]')
end
end
end
-- ####################################################################
-- some general info first
p.add_separator(infobox, 'General Info')
-- designer
if has_arg('developer') then
local designers = mw.html.create('td'):attr('style', 'width: 99%;')
designers:wikitext('[[designer::' .. arg('developer') .. '| ]][[' .. arg('developer') .. ']]')
for i = 2, 10 do
if not has_arg('developer ' .. i) then break end
designers:wikitext(', [[designer::' .. arg('developer ' .. i) .. '| ]][[' .. arg('developer ' .. i) .. ']]')
end
infobox:node(p.add_entry('Designer', designers))
end
-- manufacturer
if has_arg('manufacturer') then
local manufacturers = '[[manufacturer::' .. arg('manufacturer') .. '| ]][[' .. arg('manufacturer') .. ']]'
for i = 2, 10 do
if not has_arg('manufacturer ' .. i) then break end
manufacturers = manufacturers .. ', [[manufacturer::' .. arg('manufacturer ' .. i) .. '| ]][[' .. arg('manufacturer ' .. i) .. ']]'
end
infobox:node(p.add_entry('Manufacturer', mw.html.create('td'):wikitext(manufacturers)))
end
-- release date
if has_arg('first launched') or has_arg('first announced') then
local release = mw.html.create('td')
if has_arg('first announced') then
release:wikitext('[[first announced::' .. arg('first announced') .. ']] (announced)')
end
if has_arg('first launched') then
if has_arg('first announced') then
release:wikitext('<br>')
end
release:wikitext('[[first launched::' .. arg('first launched') .. ']] (launched)')
end
infobox:node(p.add_entry('Introduction', release))
end
if has_arg('fate') then
infobox:node(p.add_entry('Fate', mw.html.create('td'):wikitext('[[fate::' .. arg('fate') .. ']]')))
end
-- ####################################################################
-- some general info first
p.add_separator(infobox, 'Microarchitecture')
-- ISA
if has_arg('isa') or has_arg('isa family') then
local isa = mw.html.create('td'):wikitext('[[isa::' .. arg('isa') .. ']]')
for i = 2, 10 do
if not has_arg('isa ' .. i) then break end
isa:wikitext(', [[isa::' .. arg('isa ' .. i) .. ']]')
end
if has_arg('isa family') then
isa:wikitext(' ([[isa family::' .. arg('isa family') .. ']])')
end
infobox:node(p.add_entry('ISA', isa))
end
-- microarch
if has_arg('microarch') then
local microarchs = mw.html.create('td')
microarchs:wikitext('[[microarchitecture::' .. arg('microarch') .. '| ]]')
microarchs:wikitext('[[' .. mw.ustring.lower(arg('developer')) .. '/microarchitectures/' ..
mw.ustring.lower(arg('microarch')) .. '|' .. arg('microarch') .. ']]')
for i = 2, 10 do
if not has_arg('microarch ' .. i) then break end
microarchs:wikitext(', [[microarchitecture::' .. arg('microarch ' .. i) .. '| ]]')
microarchs:wikitext('[[' .. mw.ustring.lower(arg('developer')) .. '/microarchitectures/' ..
mw.ustring.lower(arg('microarch ' .. i)) .. '|' .. arg('microarch ' .. i) .. ']]')
end
infobox:node(p.add_entry('Microarchitecture', microarchs))
end
-- word size
if has_arg('word') then
infobox:node(p.add_entry('Word Size', mw.html.create('td'):wikitext('[[word size::' .. arg('word') .. '| ]]' .. arg('word'))))
end
-- process
if has_arg('proc') then
local process = mw.html.create('td'):wikitext('[[process::' .. arg('proc') .. ']]')
for i = 2, 10 do
if not has_arg('proc ' .. i) then break end
process:wikitext(', [[process::' .. arg('proc ' .. i) .. ']]')
end
infobox:node(p.add_entry('Process', process))
end
-- Technology
if has_arg('tech') then
infobox:node(p.add_entry('Technology', mw.html.create('td'):wikitext('[[technology::' .. arg('tech') .. ']]')))
end
-- Clock
if has_arg('clock') then
infobox:node(p.add_entry('Clock', mw.html.create('td'):wikitext(arg('clock'))))
elseif has_arg('clock min') then
infobox:node(p.add_entry('Clock', mw.html.create('td'):wikitext(arg('clock min') .. ' - ' .. arg('clock max'))))
end
-- ####################################################################
-- ####################################################################
-- Packaging
if has_arg('package module 1') then
p.add_separator(infobox, 'Packaging')
for i = 1, 10 do
if has_arg('package module ' .. i) then
infobox
:tag('tr'):tag('td'):attr('colspan', '2'):attr('style', 'padding: 5px;')
:wikitext(frame:preprocess(arg('package module ' .. i)))
end
end
end
-- ####################################################################
-- ####################################################################
-- Successon
if has_arg('successor') or has_arg('predecessor') then
add_header(infobox, 'Succession')
local s = infobox:tag('tr')
local td = s:tag('td'):attr('colspan', '2')
local d1 = td:tag('div'):attr('style', 'display: inline-flex;')
local d2 = td:tag('div'):attr('style', 'display: inline-flex; float: right;')
if has_arg('predecessor') then
local list
if has_arg('predecessor link') then
list = '[[' .. arg('predecessor link') .. '|' .. arg('predecessor') .. ']]'
else
list = '[[' .. arg('predecessor') .. ']]'
end
for i = 2, 10 do
if not has_arg('predecessor ' .. i) then break end
if has_arg('predecessor ' .. i .. ' link') then
list = list .. '<br>[[' .. arg('predecessor ' .. i .. ' link') .. '|' .. arg('predecessor ' .. i) .. ']]'
else
list = list .. '<br>[[' .. arg('predecessor ' .. i) .. ']]'
end
end
d1:tag('div')
:attr('style', 'float: left; padding-right: 10px; margin: auto 5px;')
:wikitext('<i class="fa fa-chevron-left"></i>')
d1:tag('div')
:attr('style', 'float: left;')
:wikitext(list)
end
if has_arg('successor') then
local list
if has_arg('successor link') then
list = '[[' .. arg('successor link') .. '|' .. arg('successor') .. ']]'
else
list = '[[' .. arg('successor') .. ']]'
end
for i = 2, 10 do
if not has_arg('successor ' .. i) then break end
if has_arg('successor ' .. i .. ' link') then
list = list .. '<br>[[' .. arg('successor ' .. i .. ' link') .. '|' ..
arg('successor ' .. i) .. ']]'
else
list = list .. '<br>[[' .. arg('successor ' .. i) .. ']]'
end
end
d2:tag('div')
:attr('style', 'float: left;')
:wikitext(list)
d2:tag('div')
:attr('style', 'float: right; padding-left: 10px; margin: auto 5px;')
:wikitext('<i class="fa fa-chevron-right"></i>')
end
end
infobox:wikitext('[[instance of::core| ]]')
return infobox
end
return p