From WikiChip
Difference between revisions of "Module:supercomputer"
(Created page with "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 fun...") |
|||
Line 116: | Line 116: | ||
-- some general info first | -- some general info first | ||
p.add_separator(infobox, 'General Info') | p.add_separator(infobox, 'General Info') | ||
+ | |||
+ | -- #################################################################### | ||
+ | -- #################################################################### | ||
+ | -- Successon | ||
+ | if has_arg('successor') or has_arg('predecessor') then | ||
+ | p.add_separator(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 | ||
+ | -- Contemporary | ||
+ | if has_arg('contemporary') then | ||
+ | p.add_separator(infobox, 'Contemporary') | ||
+ | |||
+ | local s = infobox:tag('tr') | ||
+ | local td = s:tag('td'):attr('colspan', '2') | ||
+ | |||
+ | td:attr('style', 'text-align: center;') | ||
+ | |||
+ | local list | ||
+ | if has_arg('contemporary link') then | ||
+ | list = '[[' .. arg('contemporary link') .. '|' .. arg('contemporary') .. ']]' | ||
+ | else | ||
+ | list = '[[' .. arg('contemporary') .. ']]' | ||
+ | end | ||
+ | for i = 2, 10 do | ||
+ | if not has_arg('contemporary ' .. i) then break end | ||
+ | if has_arg('contemporary ' .. i .. ' link') then | ||
+ | list = list .. '<br>[[' .. arg('contemporary ' .. i .. ' link') .. '|' .. arg('contemporary ' .. i) .. ']]' | ||
+ | else | ||
+ | list = list .. '<br>[[' .. arg('contemporary ' .. i) .. ']]' | ||
+ | end | ||
+ | end | ||
+ | |||
+ | td:wikitext(list) | ||
+ | end | ||
return infobox | return infobox |
Revision as of 23:49, 3 February 2019
Documentation for this module may be created at Module:supercomputer/doc
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 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)
if has_arg(name) then
return origArgs[name]
end
return ''
end
function p.set_val(prop, val)
p.frame:preprocess('{{#set: ' .. prop .. '=' .. val .. '}}')
end
function p.supercomputer(frame)
p.frame = frame
if frame == mw.getCurrentFrame() then
origArgs = frame:getParent().args
else
origArgs = frame.args
end
local infobox = mw.html.create('table')
p.set_val('instance of', 'supercomputer')
-- same for category
infobox:wikitext('[[Category:all supercomputers]]')
infobox
:attr('class', 'infobox')
infobox
:tag('tr')
:tag('td'):attr('colspan', '2')
:tag('small'):attr('style', 'float: left; font-weight: bold;')
:wikitext('[[Special:FormEdit/supercomputer/' .. 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(arg('name'))
p.set_val('name', arg('name'))
end
-- image
if has_arg('image') then
local image = p.add_file_prefix(arg('image'))
local image_size = has_arg('image size') and arg('image size') or "200px"
infobox
:tag('tr')
:tag('td')
:attr('style', 'text-align: center;')
:attr('colspan', '2')
-- make sure it's the ogimage
:wikitext('[[' .. image .. '|link=|class=wikichip_ogimage|' .. image_size .. ']]')
p.set_val('main image', image)
-- add a caption, if provided
if has_arg('caption') then
infobox
:tag('tr')
:tag('td')
:attr('style', 'text-align: center;')
:attr('colspan', '2')
:wikitext(arg('caption'))
p.set_val('main image caption', arg('caption'))
end
elseif not has_arg('no image') then
infobox
:tag('tr')
:tag('td')
:attr('style', 'text-align: center;')
:attr('colspan', '2')
:wikitext('[[File:no photo (ic).svg|link=|200px]]')
end
-- ####################################################################
-- some general info first
p.add_separator(infobox, 'General Info')
-- ####################################################################
-- ####################################################################
-- Successon
if has_arg('successor') or has_arg('predecessor') then
p.add_separator(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
-- Contemporary
if has_arg('contemporary') then
p.add_separator(infobox, 'Contemporary')
local s = infobox:tag('tr')
local td = s:tag('td'):attr('colspan', '2')
td:attr('style', 'text-align: center;')
local list
if has_arg('contemporary link') then
list = '[[' .. arg('contemporary link') .. '|' .. arg('contemporary') .. ']]'
else
list = '[[' .. arg('contemporary') .. ']]'
end
for i = 2, 10 do
if not has_arg('contemporary ' .. i) then break end
if has_arg('contemporary ' .. i .. ' link') then
list = list .. '<br>[[' .. arg('contemporary ' .. i .. ' link') .. '|' .. arg('contemporary ' .. i) .. ']]'
else
list = list .. '<br>[[' .. arg('contemporary ' .. i) .. ']]'
end
end
td:wikitext(list)
end
return infobox
end
return p